I am trying to use an image I made in photoshop as the background for my GUI. How do I do that? also I made some images I want to display in the button backgrounds after the action is performed...
Asked
Active
Viewed 364 times
1 Answers
1
For the JButton, use this:
JButton button = new JButton("Button Name", new ImageIcon("foo.png");
The Panel is a bit more interesting. This is a good method, though:
ImagePanel panel = new ImagePanel(new ImageIcon("foo.png").getImage());

Jon Egeland
- 12,470
- 8
- 47
- 62
-
1if you want to change the image later. Each Object has a `setBackgroundImage()` method, too. – Jon Egeland Dec 04 '11 at 03:25
-
1
-
@Jeffrey I was going to put the link but forgot where it was. Thanks. – Jon Egeland Dec 04 '11 at 03:26
-
@MatthewKemnetz you can specify the location using things like `../foo.png` for the above directory, or `images/foo.png` to go into an images folder to find the image. Google how to find paths to files. – Jon Egeland Dec 04 '11 at 03:28
-
[link] (http://www.wildcrest.com/Software/J2PrinterWorks/documentation/api/com/wildcrest/j2printerworks/ImagePanel.html) is the API for the class. I don't know where the actual library is, but `JPanel` works roughly the same. – Jon Egeland Dec 04 '11 at 03:31
-
2-1 button.icon != button.background or in other words: when setting the icon, the text will _not_ be shown on top of it (as it would with a background image) – kleopatra Dec 04 '11 at 11:33
-