Java 如何更改按钮的颜色,而不仅仅是按钮周围的边框?

Java 如何更改按钮的颜色,而不仅仅是按钮周围的边框?,java,swing,jbutton,Java,Swing,Jbutton,我想更改按钮的背景色和前景色。我使用了setBackground、setForeground和set不透明(true),它适用于前景,但不适用于按钮的背景。按钮周围有点像黑色边框,但我希望按钮本身是黑色的。我怎么修理它 this.closeButton = new JButton ("Close"); this.closeButton.setBackground(Color.BLACK); this.closeButton.setForeground(Color.PINK);

我想更改按钮的背景色和前景色。我使用了setBackground、setForeground和set不透明(true),它适用于前景,但不适用于按钮的背景。按钮周围有点像黑色边框,但我希望按钮本身是黑色的。我怎么修理它

this.closeButton = new JButton ("Close");
    this.closeButton.setBackground(Color.BLACK);
    this.closeButton.setForeground(Color.PINK);
    this.closeButton.setOpaque(true);

您可以这样做:this.closeButton.setTextColor(Color.PINK); 取消注释行:this.closeButton.setForeground(Color.PINK)

由look-and-feel代理提供“边框”。您可以通过调用
按钮来“禁用”它

这可能符合你的要求,也可能不符合你的要求


编辑标记以指定哪个用户界面工具包:JavaFX、Swing、SWT、Vaadin等。检查
java.Swing.JButton
没有
setTextColor
方法,您可能会想到JavaFX
JButton button = new JButton("Close");
button.setBackground(Color.BLACK);
button.setForeground(Color.PINK);
button.setBorderPainted(false);
button.setOpaque(true);