如果我使用 JGoodies,如何更改 JButton 的颜色WindowsLookAndFeel
?更改颜色后,单击按钮时仍应有一些视觉指示;颜色渐变和点击动画不必与 JGoodies 中的相同。
使用setBackground()
andsetForeground()
只改变按钮轮廓和按钮文本的颜色:
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()
但这似乎没有任何效果。