this.getContentPane().setLayout(BorLay);
this.getContentPane().add(JPan,BorderLayout.CENTER);

解决方案 »

  1.   

    编译没有问题,可是运行时,就会有Runtime异常。楼主一看错误提示就知道了。
    同意 superpig(黄飞鸿)
      

  2.   

    setLayout
    public void setLayout(LayoutManager manager)By default the layout of this component may not be set, the layout of its contentPane should be set instead. For example: 
     thisComponent.getContentPane().setLayout(new GridLayout(1, 2))
     An attempt to set the layout of this component will cause an runtime exception to be thrown. Subclasses can disable this behavior. Overrides:
    setLayout in class Container
    Parameters:
    manager - the LayoutManager 
    Throws: 
    Error - if called with rootPaneChecking true
    See Also:
    setRootPaneCheckingEnabled(boolean)----------------------------------------------------------------------------------
    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);
      

  3.   

    我个人觉得JFrame继承Frame,但又留了一个没用的add方法,sun的做法很不明智。至少应该在用户用oJFrame.add(XXXX)的时候,来个编译级的Warning!这样就不会出现楼主的问题了。