选中时如何更改 JButton 图标? [英] How to change JButton Icon when selected?

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

问题描述

我想在用户按下/释放按钮时更改 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);

参考:http://www.leepoint.net/notes-java/GUI/components/20bu​​ttons/23buttonicons.html

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

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