How can I create in a Swing interface a toggle image button? I have two images, imageon.jpg and imageoff.jpg,and I basically want a clickable element that toggles the images and fires an event.
Update: Is there a way to override the usual ‘chrome’ around the image? I would prefer a simple image to a button with an image inside.
Load the images with
ImageIcon. Create aJToggleButton. Then apply the icons withAbstractButton.setIcon/setPressedIcon/setSelectedIcon. Remove the border withAbstractButton.setBorderPainted(false).