Swing implements tab function (JTabbedPane)
First create the JTabbedPane object, the constructor can use JTabbedPane(int tabPlacement). tabPlacement is a field that JTabbedPane inherits from interface javax.swing.SwingConstants. It can be BUTTOM, TOP, etc. The following code looks like:
JFrame jframe = new JFrame("TEST"); <a href="http://lib.csdn.net/base/docker" class='replace_word' target='_blank' style='color:#df3434; font-weight:bold;'>Container</a> c = jframe.getContentPane(); // Create the options pane and place the settings tab on the upper JTabbedPane tabPane = new JTabbedPane(JTabbedPane.TOP); // Add to the window c.add(tabPane); Calling the addTab function can enable adding information to the tab. There are also several addTabs, among which void addTab(String title, Component component) is simply used, so that the tab can have a title and add the information component to this tab. Generally, component is a Panel, put a Panel that has been designed into this tab. The following code looks like:
// Create a new Panel, this Panel should contain the information you want to display TabPanel tabPanel1 = new TabPanel (); // Add Panel to this tabPane.addTab("TAB1", tabPanel1); // Multiple tabs can be added according to this mode... After adding the code, you can choose which tab to display by default and use setSelectedIndex(int index). I select the first tab and use the following code:
// Select the first option page as the currently selected option page tabPane.setSelectedIndex(0);
Thank you for reading, I hope it can help you. Thank you for your support for this site!