Java Swing Implementation tab feature (JTabbedPane) instance code _java

Source: Internet
Author: User
Tags knowledge base

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.