【发布时间】:2015-12-12 07:45:18
【问题描述】:
如果我使用 JGoodies WindowsLookAndFeel,如何更改 JButton 的颜色?更改颜色后,单击按钮时仍应有一些视觉指示;颜色渐变和点击动画不必与 JGoodies 中的相同。
使用setBackground() 和setForeground() 只会改变按钮轮廓和按钮文本的颜色:
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() 中的颜色,但这似乎没有任何效果。
【问题讨论】:
-
你用的是什么windows版本?
-
我使用的是 Windows 8
标签: java swing look-and-feel jgoodies