3

So I started working on a project, and after some research of JFrame, I tried this to get my window for the project:

ImageIcon hello = new ImageIcon("C:\\Users\\JP\\Desktop\\hello.jpeg");

JFrame frame = new JFrame("Test");
frame.setSize(640,480);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setBackground(Color.GREEN);
frame.setIconImage(hello.getImage());

The frame comes up in it's correct size, but does not display the icon or have the correct background color.

Alvin Bunk
  • 7,621
  • 3
  • 29
  • 45
jpthesolver2
  • 1,107
  • 1
  • 12
  • 22
  • The `setIconImage` sets the image for the title bar or when the window is minimized. If you want the image to show on the frame add it to a `JLabel` and add the `JLabel` to the `JFrame` – Jayfray Dec 29 '16 at 18:44
  • 4
    Possible duplicate of [Setting background color for the JFrame](http://stackoverflow.com/questions/1081486/setting-background-color-for-the-jframe) – user812786 Dec 29 '16 at 18:49
  • You would set the background of the JFrame's contentPane and not the JFrame itself. `frame.getContentPane().setBackground(Color.GREEN);` – DontKnowMuchBut Getting Better Dec 29 '16 at 19:00

1 Answers1

0

If you are looking to change the background of your frame, you should take a look at this Setting background color of JFrame, but either way I recommend you use the design tab of window builder, because that can make your life much easier, and such stuff can be manipulated easily. (How to open a Java form in design view?)