0

I put this in the main method, but the background won't show. Is there a draw image that I have to put after it or something to make the background show?

//background image
JLabel contentPane = new JLabel ();
JFrame frame = new JFrame ();
contentPane.setIcon (new ImageIcon ("background.png"));
contentPane.setLayout (new BorderLayout ());
frame.setContentPane (contentPane);
MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
  • 1- Does the image load? 2- Are you adding anything else to the frame? 3- Don't use `JLabel` for this, it doesn't calculate the preferred size based on its child components, it only uses the image and text properties of the label – MadProgrammer Jan 15 '15 at 02:17
  • 1
    Something like [this example](http://stackoverflow.com/questions/18393971/having-images-as-background-of-jpanel/18394047#18394047) might be better. You should also use `ImageIO.read` over `ImageIcon(String)` to load images, it will at least throw an exception if the image can't be loaded. See [Reading/Loading an Image](http://docs.oracle.com/javase/tutorial/2d/images/loadimage.html) for more details – MadProgrammer Jan 15 '15 at 02:19

0 Answers0