Results 1 to 3 of 3
  1. #1
    mando is offline Member
    Join Date
    Aug 2011
    Posts
    2
    Rep Power
    0

    Default JPanel colors don't show

    I have written a very simple gui, which I am going to use to build upon. I don't see a problem with my code except that when I run it the colors don't appear. What am I doing wrong? This is my code:
    JFrame frame = new JFrame();
    frame.setSize(250,100);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);

    JPanel tophalf = new JPanel();
    JPanel bottomhalf = new JPanel();
    frame.getContentPane() .add(BorderLayout.NORTH, tophalf);
    frame.getContentPane() .add(BorderLayout.SOUTH, bottomhalf);
    tophalf.setBackground(Color.white);
    bottomhalf.setBackground(Color.darkGray);

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,395
    Rep Power
    25

    Default

    Try not setting it visible until it is ready to be seen.

  3. #3
    mando is offline Member
    Join Date
    Aug 2011
    Posts
    2
    Rep Power
    0

Similar Threads

  1. Last JLabel I add to JPanel doesnt show up
    By Ambergahill in forum New To Java
    Replies: 6
    Last Post: 01-29-2014, 08:07 PM
  2. FrameView doesn't show new JPanel until I resize
    By metazone in forum SWT / JFace
    Replies: 3
    Last Post: 01-05-2012, 03:52 PM
  3. JPanel: Show Tooltip on click
    By knuth in forum New To Java
    Replies: 2
    Last Post: 10-01-2009, 04:46 PM
  4. How show a popWindow that have JPanel like parent
    By Wolverine in forum AWT / Swing
    Replies: 4
    Last Post: 05-23-2009, 08:59 AM
  5. netbeans 6.0 not show commpunent or show blank page
    By fahimaamir in forum NetBeans
    Replies: 1
    Last Post: 01-26-2008, 06:20 AM

Posting Permissions

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