-
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);
-
Try not setting it visible until it is ready to be seen.
-