简单,你只要把this.setBackground(c);改为以下就OK了, 哈哈..........
this.getContentPane().setBackground(c);

解决方案 »

  1.   

    呵,真的简单,不过this.setBackground(c);这句话有什么意思啊?它改变的是什么东东?
      

  2.   

    什么的背景色?但是为什么只能用
    this.getContentPane().setBackground(c);
    来改变背景色,而不能用this.setBackground(c);
    来改变背景色呢?清楚一点,好吗?
    在线等待给分!
      

  3.   

    那this.setBackground(c);与this.getContentPane().setBackground();这两句话有什么区别的吗?在线等待给分
      

  4.   

    this是指的该类
    this.getContentPane()得到这个类的panel属性
    一般来说,在使用show()之后,出现在屏幕上的是这个类的panel属性
      

  5.   

    唔,对不起,各位还是没有回答到正题上,我知道this是指当前的对象,可是我想知道,
    this.setBackground(c);与this.getContentPane().setBackground();
    的区别何在?为什么调用对象的方法不能设置背景色,而调用对象的pane对像就可以设置它的背景色?
    这个问题应该不是很难吧,痛苦啊……………
      

  6.   

    Javadoc里讲的很清楚。The JFrame class is slightly incompatible with Frame. Like all other JFC/Swing top-level containers, a JFrame contains a JRootPane as its only child. The content pane provided by the root pane should, as a rule, contain all the non-menu components displayed by the JFrame. This is different from the AWT Frame case. For example, to add a child to an AWT frame you'd write:        frame.add(child);
     However using JFrame you need to add the child to the JFrame's content pane instead: 
           frame.getContentPane().add(child);
     The same is true for setting layout managers, removing components, listing children, and so on. All these methods should normally be sent to the content pane instead of the JFrame itself. The content pane will always be non-null. Attempting to set it to null will cause the JFrame to throw an exception. The default content pane will have a BorderLayout manager set on it. 
      

  7.   

    看到了吧,“The content pane will always be non-null. Attempting to set it to null will cause the JFrame to throw an exception.”
    contentpane会显示在没有MenuBar的地方,而且不会是null!!!
      

  8.   

    为什么要在构造函数中调用repaint()方法??
    应该有点问题吧,show()的时候系统会调用的啊。。
      

  9.   

    小马哥:
    即便我不用repaint方法,也不会显示背景的,呵呵,但也谢谢您的参与