0

I want to set a image background on my JFrame thanks to automated generated code by Netbeans.

Unfortunately, I am facing this exact problem : http://www.areaofthoughts.com/2011/08/netbeans-jframe-properties-iconimage.html

When I tried to add it graphically, on details of iconImage, I have this error : "Custom editing of this property is not supported"

I tried the solution given in the link above, but unfortunately, this code doesn't work:

public ArrayList<Image> getIconImages() {
   ArrayList<Image> imageList = new ArrayList();
   imageList.add(getClass().getResource("/<resource_path>" +
     "/image.png")).getImage());
   return imageList;  
}

What is the problem in this code, and how can I fix this problem of background (by any way?).

Please note that when I did it for label with Netbeans, I had no problem for doing it. The generated code was, for example, the following:

jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/main/myimage/img.png")));    
GEOCHET
  • 21,119
  • 15
  • 74
  • 98
user1638875
  • 105
  • 3
  • 10

1 Answers1

1

You generally have two choices.

1- Create a custom JPanel that can paint the image as part of its background, then add this to your frame (once compiled, it can be dragged into the designer), have a look at Performing Custom Painting

2- Set the layout of the JFrame to BorderLayout, add a JLabel to the frame. Assign a image/icon to the label. Set the layout of the label to what ever you need and your components toit.

You may need to adjust the horizontal & vertical position of the icon within the label to suit your needs

For an example, check out this previous answer Place JLabel on top of JLabel with image in

Community
  • 1
  • 1
MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
  • I see. So new question, how to place some JLabel behind all components that already exists with "Design"(graphical way) part of netbeans? – user1638875 Sep 07 '12 at 00:18
  • The simplest way I can think off is to either set the frame's `contentPane` to the background component (you'll need to code this so it appears before the `initComponents` method) or simply drag you're resulting component into the designer and drop your components ontop of it... – MadProgrammer Sep 07 '12 at 00:54