jus a simple question, how would i code a button so that if the NUMPAD 0 was pressed, it would change the buttons icon? i am currently using an image for the button and wish to change that image to a different upon select.
I assume the problem is the image switching, not catching the Numpad 0 keystroke.
The hard way:
Make a JButton extension (ImageButton ?), introduce a new constructor that has two Images
as parameters. Then override the paintComponent(Graphics g) method in the
JButton. In this method you paint one or the other image, based on a flag that is
set by a method you include in the ImageButton class, say, setImage(boolean onOff). This method is invoked on every Numpad 0 keystroke.
The easy way:
Make your button a JToggleButton, and set the images using the setSelectedIcon and
the setIcon methods. Switch image by invoking the setSelected method for the button.
thanks for that mate! i took the asy option lol!!!
on the off chance can u recommend any easy, Zoom, pan and rotate methods / code that i can implement for my buttons? i have zoom code but its very comprehensive!!!
if not its ok thanks for ur help... much appreciated!
Bookmarks