首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在JGoodies WindowsLookAndFeel中更改JButton的颜色

在JGoodies WindowsLookAndFeel中更改JButton的颜色
EN

Stack Overflow用户
提问于 2015-09-16 06:05:03
回答 1查看 395关注 0票数 5

如果我使用的是JGoodies WindowsLookAndFeel,如何更改JButton的颜色?更改颜色后,按钮在单击时仍应具有一些视觉指示;颜色渐变和单击动画不必与JGoodies中的相同。

使用setBackground()setForeground()仅更改按钮轮廓和按钮文本的颜色:

代码语言:javascript
复制
import com.jgoodies.looks.windows.WindowsLookAndFeel;
...

public class Test {
    public static void main(String[] args) throws UnsupportedLookAndFeelException {
        UIManager.setLookAndFeel(new WindowsLookAndFeel());

        JFrame frame = new JFrame();
        frame.setSize(50, 100);
        JButton button = new JButton("Button");
        button.setBackground(Color.GREEN);
        button.setForeground(Color.RED);
        button.setOpaque(true);
        frame.add(button);
        frame.setVisible(true);
    }
}

我想为按钮的整个区域设置颜色,而不仅仅是轮廓。(如果未使用WindowsLookAndFeel,则会发生这种情况。)

我也尝试过在com.jgoodies.looks.windows.WindowsBorders#getButtonBorder()中更改颜色,但似乎没有任何效果。

EN

回答 1

Stack Overflow用户

发布于 2015-09-29 23:41:22

尝试将调用添加到setContentAreaFilled:

代码语言:javascript
复制
button.setContentAreaFilled(false); //must be before setOpaque
button.setOpaque(true);

或者,您可以覆盖JButton并绘制:Change JButton gradient color, but only for one button, not all

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32596453

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档