<分区>
我正在使用 netbeans 创建桌面应用程序,我正在尝试使用代码更改 JButton、btn1 的背景颜色
btn1.setBackground(Color.Red)
但这行不通。不改变按钮的填充颜色,只改变边框颜色。如何更改背景填充?
谢谢
<分区>
我正在使用 netbeans 创建桌面应用程序,我正在尝试使用代码更改 JButton、btn1 的背景颜色
btn1.setBackground(Color.Red)
但这行不通。不改变按钮的填充颜色,只改变边框颜色。如何更改背景填充?
谢谢
最佳答案
参见 this相关问答。
In particular, you can use setForeground() to change the color of a button's text, but the corresponding setBackground() doesn't read well on some platforms. Using a Border is one alternative; a colored panel, shown below, is another.
您也可以尝试在按钮上调用 setOpaque(true)
。
关于Java 更改按钮背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10134072/