You can't add JFrame
(or another top-level component) to another component/container, but you can use getContentPane()
method of frame, to get main panel of your frame and add that to JTabbedPane
tab. Like next:
JTabbedPane tabs = new JTabbedPane();
JFrame frame = new JFrame();
frame.add(new JButton("button"));
tabs.addTab("1", frame.getContentPane());
Also you can change JFrame
to JPanel
and use that.
Read about JInternalFrame
, top-level containers.
EDIT: getContentPane()
doesn't return any decorations or JMenuBar
, this components you need to add manually, like in next example with menu:
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);