【问题标题】:Java Swing Button: setColor doesn't display the right colorJava Swing 按钮:setColor 不显示正确的颜色
【发布时间】:2018-09-20 15:31:43
【问题描述】:

在这个程序中我遇到了问题,因为按钮的颜色与我设置的不同。

...

jButton1 = new javax.swing.JButton();
jButton1.setBackground(new Color(103,175,63));
jButton1.setFont(new java.awt.Font("Futura", 1, 14));
jButton1.setForeground(Color.white);
jButton1.setText("Potvrdit");

...

(这些是唯一以某种方式设置按钮的行)

按钮图片:

我希望按钮是什么样的:

无边框按钮:

【问题讨论】:

  • 你想要什么颜色?你能添加一张你希望按钮是什么样子的图片吗?
  • 我只想要完全绿色的背景和白色的前景,但出于某种奇怪的原因,即使我很难设置它,也不会发生。图片已添加。
  • 去掉 8px 边框...
  • 这不是我的问题的重点。我的问题是出现的颜色不是我在参数中设置的真实颜色...
  • 啰嗦了,不过this example演示了基本概念

标签: java swing user-interface button


【解决方案1】:

要得到真实的背景颜色,另外setBackground()试试用:

jButton1.setOpaque(true);

此外,要删除灰色边框,您可以使用:

jButton1.setBorderPainted(false);

【讨论】:

  • 可能还需要使用setContentAreaFilled
【解决方案2】:

试试这个

 b1.setContentAreaFilled(false);
 b1.setBackground(new Color(103,175,63));
 b1.setFont(new java.awt.Font("Futura", 1, 14));
 b1.setForeground(Color.white);
 b1.setText("Potvrdit");
 b1.setOpaque(true);
 b1.setBorder(new LineBorder(new Color(103,175,63), 1, true));

【讨论】:

    猜你喜欢
    • 2020-12-09
    • 1970-01-01
    • 2018-02-05
    • 2011-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-05
    相关资源
    最近更新 更多