2015-04-12 127 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