How to change JButton Icon when selected?

点点圈 提交于 2020-01-14 13:47:07

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/12468203/how-to-change-jbutton-icon-when-selected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!