Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将JFrame插入Swing中的选项卡中_Java_Swing_Jframe_Jtabbedpane - Fatal编程技术网

Java 将JFrame插入Swing中的选项卡中

Java 将JFrame插入Swing中的选项卡中,java,swing,jframe,jtabbedpane,Java,Swing,Jframe,Jtabbedpane,我已经有了一个给定的JFrame框架,我想将它显示(插入)到JTabbedPane的选项卡中,但这是不可能的: frame = new JFrame(); frame.setBounds(100, 100, 450, 300); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mainTabs.addTab("Editor", null, frame, null); 错误是: java.lang.IllegalArgumentExc

我已经有了一个给定的
JFrame框架
,我想将它显示(插入)到
JTabbedPane
选项卡中,但这是不可能的:

frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

mainTabs.addTab("Editor", null, frame, null);
错误是:

java.lang.IllegalArgumentException: adding a window to a container
我尝试了一些解决方案,比如将框架插入
JPanel
,但也没有成功。我想把它转换成一个
InternalJFrame
,但我对此一无所知

这是插入该
帧的解决方案吗

更新

我试过这个解决方案:

 mainTabs.addTab("Editor", null, frame.getContentPane(), null);

但是我丢失了我添加的
JMenuBar

您不能将
JFrame
(或另一个顶级组件)添加到另一个组件/容器中,但可以使用
getContentPane()
frame方法获取框架的主面板,并将其添加到
JTabbedPane
选项卡中。像下一个:

JTabbedPane tabs = new JTabbedPane();
JFrame frame = new JFrame();
frame.add(new JButton("button"));
tabs.addTab("1", frame.getContentPane());
您还可以将
JFrame
更改为
JPanel
并使用它

阅读有关

编辑:
getContentPane()
不返回任何装饰或
JMenuBar
,此组件需要手动添加,如下一个菜单示例:

JTabbedPane tabs = new JTabbedPane();

JFrame frame = new JFrame();
JMenuBar bar = new JMenuBar();
bar.add(new JMenu("menu"));
frame.setJMenuBar(bar);
frame.add(new JButton("button"));

JPanel tab1 = new JPanel(new BorderLayout());
tab1.add(frame.getJMenuBar(),BorderLayout.NORTH);
tab1.add(frame.getContentPane());
tabs.addTab("1", tab1);

您不能将
JFrame
(或另一个顶级组件)添加到另一个组件/容器中,但可以使用
getContentPane()
frame方法获取框架的主面板,并将其添加到
JTabbedPane
选项卡中。像下一个:

JTabbedPane tabs = new JTabbedPane();
JFrame frame = new JFrame();
frame.add(new JButton("button"));
tabs.addTab("1", frame.getContentPane());
您还可以将
JFrame
更改为
JPanel
并使用它

阅读有关

编辑:
getContentPane()
不返回任何装饰或
JMenuBar
,此组件需要手动添加,如下一个菜单示例:

JTabbedPane tabs = new JTabbedPane();

JFrame frame = new JFrame();
JMenuBar bar = new JMenuBar();
bar.add(new JMenu("menu"));
frame.setJMenuBar(bar);
frame.add(new JButton("button"));

JPanel tab1 = new JPanel(new BorderLayout());
tab1.add(frame.getJMenuBar(),BorderLayout.NORTH);
tab1.add(frame.getContentPane());
tabs.addTab("1", tab1);

您不能将
JFrame
(或另一个顶级组件)添加到另一个组件/容器中,但可以使用
getContentPane()
frame方法获取框架的主面板,并将其添加到
JTabbedPane
选项卡中。像下一个:

JTabbedPane tabs = new JTabbedPane();
JFrame frame = new JFrame();
frame.add(new JButton("button"));
tabs.addTab("1", frame.getContentPane());
您还可以将
JFrame
更改为
JPanel
并使用它

阅读有关

编辑:
getContentPane()
不返回任何装饰或
JMenuBar
,此组件需要手动添加,如下一个菜单示例:

JTabbedPane tabs = new JTabbedPane();

JFrame frame = new JFrame();
JMenuBar bar = new JMenuBar();
bar.add(new JMenu("menu"));
frame.setJMenuBar(bar);
frame.add(new JButton("button"));

JPanel tab1 = new JPanel(new BorderLayout());
tab1.add(frame.getJMenuBar(),BorderLayout.NORTH);
tab1.add(frame.getContentPane());
tabs.addTab("1", tab1);

您不能将
JFrame
(或另一个顶级组件)添加到另一个组件/容器中,但可以使用
getContentPane()
frame方法获取框架的主面板,并将其添加到
JTabbedPane
选项卡中。像下一个:

JTabbedPane tabs = new JTabbedPane();
JFrame frame = new JFrame();
frame.add(new JButton("button"));
tabs.addTab("1", frame.getContentPane());
您还可以将
JFrame
更改为
JPanel
并使用它

阅读有关

编辑:
getContentPane()
不返回任何装饰或
JMenuBar
,此组件需要手动添加,如下一个菜单示例:

JTabbedPane tabs = new JTabbedPane();

JFrame frame = new JFrame();
JMenuBar bar = new JMenuBar();
bar.add(new JMenu("menu"));
frame.setJMenuBar(bar);
frame.add(new JButton("button"));

JPanel tab1 = new JPanel(new BorderLayout());
tab1.add(frame.getJMenuBar(),BorderLayout.NORTH);
tab1.add(frame.getContentPane());
tabs.addTab("1", tab1);