Results 1 to 7 of 7
  1. #1
    jdsflash is offline Member
    Join Date
    Nov 2009
    Posts
    3
    Rep Power
    0

    Default Jpanel and displaying graphics

    Would I use a Jpanel to display a square that I add the the panel.
    I want to display 3 panels and inside those panels i want to display a shape of a square, circle or rectangle.

    Would I use a jpanel to hold those shapes?

    How do I get this code to display my panel? It does not show up on my window.
    Java Code:
    JPanel panel1 = new JPanel();
    panel1.setSize(200, 200);
    panel1.setVisible(true);
    add( panel1 );

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,233
    Rep Power
    6

    Default

    You should be setting the "preferredSize", not the size.

  3. #3
    jdsflash is offline Member
    Join Date
    Nov 2009
    Posts
    3
    Rep Power
    0

    Default

    That gave me some warning and woudl not compile. how would i code that from my snipet above?

  4. #4
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,233
    Rep Power
    6

    Default

    Read the API to find out what the paraementers are for the method and then fix the compile errors.

  5. #5
    magnus is offline Member
    Join Date
    Nov 2009
    Posts
    2
    Rep Power
    0

    Default

    Hello jdsflash.

    Looks like you dont add your panel to the frame?
    And setSize i would replace with panel1.setPreferedSize(new Dimension(200,200));

    Java Code:
    panel1.setPreferedSize(new Dimension(200,200));
    frame.add(panel1)

    Hope that helps.

    Regards / Magnus.

  6. #6
    jdsflash is offline Member
    Join Date
    Nov 2009
    Posts
    3
    Rep Power
    0

    Default

    Thanks thats just what I needed.

    The java docs are like greek to me.

  7. #7
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,233
    Rep Power
    6

    Default

    Your welcome.

    Now if you had looked at the API earlier you would have had your answer in 1 minute rather than waiting around for someone to spoonfeed you the answer.

Similar Threads

  1. Clear Graphics Objects from Jpanel
    By DavidG24 in forum AWT / Swing
    Replies: 2
    Last Post: 05-20-2009, 09:34 PM
  2. Newbie need help on JPanel graphics
    By junpogi in forum AWT / Swing
    Replies: 7
    Last Post: 10-21-2008, 07:44 AM
  3. SWT Graphics Example
    By Java Tip in forum SWT
    Replies: 0
    Last Post: 06-28-2008, 09:28 PM
  4. graphics
    By Joe2003 in forum Advanced Java
    Replies: 4
    Last Post: 01-18-2008, 07:44 PM
  5. Graphics
    By feniger in forum New To Java
    Replies: 1
    Last Post: 12-29-2007, 04:22 PM

Posting Permissions

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