English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I have an array of JButtons all with an icon. I want to make it so that when the button is pressed, the icon disappears and the button reverts to its background color, which will be set at the same time. I know how to set thebackground image, but how do you remove the ImageIcon?

2006-11-13 07:33:42 · 3 answers · asked by snoboarder2k6 3 in Computers & Internet Programming & Design

3 answers

Reset the icon using null, e.g.
button.setIcon(null);

Note that if all you do is the above (and set the background to a color), then the button will be resized to the minimal default. To preserve the button's size, retrieve the preferredSize() before setting the icon to null, and then reset the preferred size.

2006-11-13 12:51:22 · answer #1 · answered by vincentgl 5 · 0 0

its not to hard to do that you just set the image t null. but whats better is if you make it grey out. you can do it same way sure there is a function in the inconImage class, dont have it with me at the mo, email me and ill look it up later.

2006-11-13 08:06:02 · answer #2 · answered by origamix60 3 · 0 0

Go here http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JButton.html
Find the functions you need, if the method you're looking for doesn't seem to be there, then try the next class up (the class that JButton inherits it's functionality from).
Hope this helps,

2006-11-13 08:03:58 · answer #3 · answered by scott p 3 · 0 0

fedest.com, questions and answers