JTabbedPane in Java Swing

Home  »  Java  »  Advance Java  »  Java Swing II  »  JTabbedPane


JTabbedPane in Swing enables you to group several swing component groups on the same container. To view a particular component group, you need to select the tab corresponding to the component group in the tabbed pane. To create a tabbed pane, create an instance of JTabbedPane class and add various tabs to it using the addTab() method of JTabbedPane class. The syntax to create a JTabbedPane is:



To add a tab to a tabbed pane:



The various constructors that swing provides to create a JTabbedPane are:

  1. JTabbedPane(): Creates an empty JTabbedPane with default placement of JTabbedPane.Top. The placement specifies the division of JTabbbedPane.

  2. JTabbedPane(int placement): Creates a JTabbedPane with specified placement that is passed as an argument to the constructor. The various placements for a JTabbedPane are JTabbedPane.TOP, JTabbedPane.BOTTOM, JTabbedPane..LEFT and JTabbedPane..RIGHT.

  3. JTabbedPane(int placement, int tabLayoutPolicy): Creates a JTabbedPane with the placement and tabLayoutPolicy passed as an argument to the constructor.


A JTabbedPane component provides quick access to the mulitiple JPanels using the same space and Window. Consider the following example, which shows the use of JTabbedPane to group information about an end-user.



The above listing uses JTabbedPane to group together the Personal Information, Education Qualification and Areas of Interest of an individual.

C:\>jdk1.4\bin>javac JTabbedPaneDemo.java
C:\>jdk1.4\bin>java JTabbedPaneDemo



"Output of JTabbedPaneDemo.class"


Download Complete Program

  -  



Java Swing-II


JOptionPane Class Input Dialog Boxes JSliders
JProgressBars JTables JTabbedPane
JMenu JPopupMenu JToolBar
JFileChooser JScrollBar JScrollPane
JRootPane JTextPane JTree
JSplitPane JDesktopPane JEditorPane




1 comment: