首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >着色JButton

着色JButton
EN

Stack Overflow用户
提问于 2013-09-09 21:07:56
回答 1查看 774关注 0票数 0

我用JAVA编程,我的操作系统是MAC。我正在尝试setForeground,甚至setBackground我的JButtons,但没有进展。我添加了以下内容:

代码语言:javascript
复制
button.setOpaque(true); 
button.setBorderPainted(false);

但是,仍然没有变化!如何更改我的JButtons的颜色?

以下是我的代码:

代码语言:javascript
复制
    public class New_button extends JButton{
    String up = new String("<html><font color=BLACK>^<size=50></font></html>");
    String down = new String("<html><font color=BLACK>v<size=50></font></html>");
    double value;
    int foldChange;

    public New_button(double val, int foldChan) {
        value = val;
        foldChange = foldChan;
        this.setSize(30, 30);
        this.setFont(this.getFont().deriveFont(50.0f));
        this.setBorder(null);
    }

    public void changeColor(double value){
         try {
                UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
             } catch (Exception e) {
                        e.printStackTrace();
             }
        if(value > 0.05){
            this.setForeground(Color.YELLOW);
            this.setOpaque(true);
            this.setBorderPainted(false);

        }
        else{
            this.setForeground(Color.RED);
            this.setOpaque(true);
            this.setBorderPainted(false);
        }
    }

    public void changeLable(int foldChange){
        if(foldChange == 1)
            this.setText(up);
        else
            this.setText(down);
    }    
}

谢谢

EN

回答 1

Stack Overflow用户

发布于 2013-09-09 21:09:38

请按此方式检查:

代码语言:javascript
复制
JButton button = new JButton("test");
button.setBackground(Color.RED);
button.setOpaque(true);

source

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

https://stackoverflow.com/questions/18698961

复制
相关文章

相似问题

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