-1
这实际上是我的代码。JButton.setBackground函数无法正常工作
JButton but = new JButton("=");
but.setOpaque(true);
if (but.getText() == "=")
{
but.setForeground(Color.WHITE);
but.setBackground(Color.BLUE);
but.addActionListener(listen);
but.setPreferredSize(new Dimension(30, 30));
numberZone.add(but);
}
setForeground功能,但不是setBackground。 我尝试setOpaque函数,但没有任何更改。 我在一个mac OSX系统上。我不知道这是否重要。
感谢和抱歉我的英语错误。
你是对的大约相等的功能。我尝试过,但setBackground函数总是不起作用。 – gillioa 2014-11-05 00:04:01
@gillioa:显示更多代码和背景信息。最好的代码是[mcve](http://stackoverflow.com/help/mcve)。 – 2014-11-05 00:16:17