【问题标题】:How to change JButton Icon when selected?选择时如何更改JButton图标?
【发布时间】:2012-09-17 22:58:45
【问题描述】:

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

选择 JButton 时的图标图像

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

我该怎么做?

【问题讨论】:

    标签: java swing applet icons jbutton


    【解决方案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);
    

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

    【讨论】:

    • @BernardoVale 阅读 api 文档有助于减少那些感觉愚蠢的时刻 :-)
    猜你喜欢
    • 2015-05-21
    • 2019-01-10
    • 1970-01-01
    • 1970-01-01
    • 2023-03-12
    • 2016-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多