选择后如何更改JButton Icon? [英] How to change JButton Icon when selected?

查看:180
本文介绍了选择后如何更改JButton Icon?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在用户按下/释放按钮时更改JButton图标。

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

选择JButton时的图标图像

A icon image when the JButton were selected

取消选择JButton并释放JButton时的图标图像:

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

我该怎么做?

推荐答案

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/20bu​​ttons/23buttonicons.html

这篇关于选择后如何更改JButton Icon?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆