我想使用 JFrame 从我的 Java 应用程序发送系统通知,我想在这个通知上设置背景颜色。现在通知有效,但我无法更改背景颜色。 这是代码:
public class NotificationFrame extends JFrame{
/**
*
*/
private static final long serialVersionUID = -2902763674924791105L;
public NotificationFrame(){
super();
setUndecorated(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBackground(Color.red);
setMinimumSize(new Dimension(300, 100));
add(new LabelFormat("Notifiche"));
}
}
使用这段代码,我的 JFrame 的背景颜色永远是灰色。
最佳答案
您实际上是想更改 JFrame 的 contentPane,而不是 JFrame 本身。
改变
setBackground(Color.red);
到
getContentPane().setBackground(Color.red);
关于java - 如何在 JFrame 中更改背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33170623/