```````

解决方案 »

  1.   

    JFrame 中的 rootPane 和 JRootPane 中的 contentPane 都是受保护类型.
    你不能直接调用它们像这样:rootPane.contentPane.add()
    如果楼主强烈要求使用它们,而抛弃getContentPane()方法,那么建议使用下面类似代码:import javax.swing.*;public class Test extends JFrame 
    {
    private JButton btnOk = new JButton("OK");

    public Test()
    {
    super();

    getRootPane().getContentPane().add(btnOk);

    setSize(400,450);
    setVisible(true);
    }

    public static void main(String[] args)
    {
    Test application = new Test();

    application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    }