简体   繁体   中英

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

在此输入图像描述

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

未选中/释放时

How can I do this?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM