Merge two tabs in Java Swing
Thank you for viewing. I'm a beginner with Java swing. I'm trying to merge two tabs in an application. The tabs are created in this way:
pane=new JTabbedPane(JTabbedPane.TOP, JTabbedPane.WRAP_TAB_LAYOUT); pane.add(panel1); pane.add(panel2);
I'd like to开发者_如何学Go have the contents of panel1 and panel2 merged together, with panel2 displayed underneath panel1. I know this may seem like a very simple question, but I am still learning. Thanks guys.
Edit: panel1 and panel2 are both JScrollPane
Create a third JPanel that uses whatever layout would work (BorderLayout or BoxLayout come to mind), and add your two JPanels to the third one. Then add the third one to the tabbed pane.
edit: this is a little confusing: "Edit: panel1 and panel2 are both JScrollPane" So these are in fact JScrollPanes, not JPanels? Regardless, my suggestion above still works. :)
Most important though: study how to use layout managers and components such as JPanels etc on the Oracle Swing Tutorials: Layout Manager Tutorial
JPanel containerPanel = new JPanel();
containerPanel.setLayout(new BoxLayout(containerPanel, BoxLayout.PAGE_AXIS));
containerPanel.add(panel1);
containerPanel.add(panel2);
pane.add(containerPanel);
精彩评论