2015-10-16 187 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);