我扩展一个JFrame类,不想通过getContentPane()来获得内容框,而是用rootPane.contentPane.add()来添加JPanel,却不可以通过编译,怎么回事呀 ``````` 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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); }} Java中线程池中断子线程的问题。有代码,有经验的来看看。 Java 在linux下连接SQLite的问题 sun.net.ftp.FtpClient 这个类属从哪里获得? 招聘JAVA和Delphi开发人员 大家给我出出主意!! 本来想让一个球移动,怎么变成一条直线了 请问关于jcreator pro的工程编译出错的问题 在循环中申明变量会导致不良后果吗? 求对图象放大缩小的算法 大家帮我出个主意吧。。 菜鸟问题: 文本区不能显示(awt)。 一个排序的问题
你不能直接调用它们像这样: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);
}
}