-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