如果我使用的是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()中更改颜色,但似乎没有任何效果。
发布于 2015-09-29 23:41:22
尝试将调用添加到setContentAreaFilled:
button.setContentAreaFilled(false); //must be before setOpaque
button.setOpaque(true);或者,您可以覆盖JButton并绘制:Change JButton gradient color, but only for one button, not all
https://stackoverflow.com/questions/32596453
复制相似问题