Results 1 to 4 of 4
  1. #1
    trey is offline Member
    Join Date
    Mar 2012
    Posts
    2
    Rep Power
    0

    Talking practicing java2D drawing, need guidance.

    hi,
    im still a newbie in java programming and i'm exploring how to draw lines, and want to add a scrollbar on the frame i made so that i can continuously add lines more lines at the end and would still be able to view those line through the scrollbar. i was able to do so but wen i start scrolling, the image is destroyed. here is my code.

    public static void main(String[] args) {
    JFrame frame = new JFrame();
    JPanel panel = new Draw();
    panel.setPreferredSize(new Dimension(3000, 240));
    JScrollPane scrollPane = new JScrollPane(panel);

    frame.add(new StaffDraw());
    frame.add(scrollPane);
    frame.setPreferredSize(new Dimension(1000, 240));
    frame.pack();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
    frame.setLocationByPlatform(true);
    frame.setResizable(true);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default Re: practicing java2D drawing, need guidance.

    Go through the forum FAQs and find out how to post code so that it retains its formatting.

    Do you really expect that anyone here can help you by looking at code that has nothing to do with custom painting?

    Java Code:
    frame.add(new StaffDraw());
     frame.add(scrollPane);
    Adding two components to the default CENTER of a JFrame's default BorderLayout is wrong. To know why, find and go through the Oracle tutorial on How to Use BorderLayout.

    Moving to AWT/Swing

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default Re: practicing java2D drawing, need guidance.

    Moved from New to Java

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    trey is offline Member
    Join Date
    Mar 2012
    Posts
    2
    Rep Power
    0

    Default Re: practicing java2D drawing, need guidance.

    sorry, just got a little upset with what im doing and didn't know whom to ask for help. it's really my first time to code java that is why i joined forums hoping that learn from other people..thanx anyway for the reply

Similar Threads

  1. Want some material for practicing loop
    By gozuhair in forum New To Java
    Replies: 11
    Last Post: 07-30-2011, 11:23 PM
  2. Practicing Concurrency
    By sunde887 in forum New To Java
    Replies: 1
    Last Post: 06-21-2011, 04:27 AM
  3. Practicing Java
    By sumithra in forum New To Java
    Replies: 4
    Last Post: 07-11-2010, 03:09 PM
  4. Java2D
    By Alex j in forum Java 2D
    Replies: 1
    Last Post: 04-07-2009, 05:59 PM
  5. A problem in practicing the array
    By dl21 in forum New To Java
    Replies: 2
    Last Post: 04-25-2008, 12:32 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •