2015-04-12 125 views
0
JFrame frame = new JFrame("New Frame"); 
    frame.setSize(1000,750); 
    frame.add(new myComponent()); 
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    frame.setVisible(true); 
    frame.setBackground(Color.pink); 

當我運行這個,框架中的背景仍然顯示爲白色,而不是粉紅色。爲什麼?框架不改變背景顏色

回答

0

試試這個

frame.getContentPane().setBackground(Color.PINK); 
+0

在哪裏我做錯了什麼? –

+0

你不能完全做你想做的事情。請閱讀[本主題]中的第一個答案(http://stackoverflow.com/questions/11268357/why-wont-my-background-color-display-in-jframe)。 [這](https://docs.oracle.com/javase/tutorial/uiswing/components/toplevel.html)可能是繼續的好地方。 – DSlomer64