2015-10-16 196 views
2

我想使用JFrame从我的Java应用程序发送系统通知,并且我想在此通知中设置背景颜色。现在通知有效,但我无法更改背景颜色。 这是代码:如何更改JFrame的背景颜色

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的背景颜色是everty时间灰色。

回答

7

你实际上想要改变JFrame的contentPane,而不是JFrame本身。
变化

setBackground(Color.red); 

getContentPane().setBackground(Color.red);