[英]How to change background color at JFrame
我想使用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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.