Swing Implementation Tab function (JTabbedPane)
The JTabbedPane object is created first, and the constructor can use JTabbedPane (int tabplacement). Tabplacement is the field that JTabbedPane inherits from the interface javax.swing.SwingConstants. It can be buttom,top and so on. As shown in the following code:
JFrame JFrame = new JFrame ("TEST");
<a href= "Http://lib.csdn.net/base/docker" class= ' Replace_word ' title= ' Docker ' a Knowledge base "target= ' _blank ' ' style= ' df3434; Font-weight:bold; ' >Container</a> C = Jframe.getcontentpane ();
Create Options pane, Set tab on upper
jtabbedpane tabpane = new JTabbedPane (jtabbedpane.top);
Add to the window
c.add (tabpane);
Calling the AddTab function enables you to add information to the tab. There are several addtab, one of which is simple with void AddTab (String title, Component Component), so that the tab can have a title and the information component is added to this tab. General component is a panel that puts a panel that has already been designed into this tab. As shown in the following code:
New Panel, this panel should contain the information you want to display
TabPanel tabPanel1 = new TabPanel ();
Add a panel to this tab TAB1
tabpane.addtab ("TAB1", tabPanel1);
You can add more than one tab to this mode ...
After adding the code, you can choose which tab to display by default, with setSelectedIndex (int index). I select the first tab with the following code:
Select the first option page Tabpane.setselectedindex for the currently selected option page
(0);
Thank you for reading, I hope to help you, thank you for your support for this site!