Bernardo Vale
Bernardo Vale

Reputation: 3544

How to change JButton Icon when selected?

I Want to change the JButton icon when user press/release the button.

A icon image when the JButton were selected

enter image description here

A icon image when the JButton were unselected and the JButton were release:

When unselected/release

How can I do this?

Upvotes: 3

Views: 5142

Answers (1)

Alvin Pradeep
Alvin Pradeep

Reputation: 618

JButton b = new JButton(Icon x); // Create button with normal icon
   b.setIcon(Icon x);
   b.setDisabledIcon(Icon x);
   b.setPressedIcon(Icon x);
   b.setSelectedIcon(Icon x);
   b.setDisabledSelectedIcon(Icon x);

ref: http://www.leepoint.net/notes-java/GUI/components/20buttons/23buttonicons.html

Upvotes: 13

Related Questions