by Dinesh Thakur Category: Swing

Sometimes a situation may arise when there are lots of components that cannot be accommodated in a single screen. In that case, tabbed pane is used to create tabs where each tab contains group of related components. When a particular tab is clicked, the components of that tab are displayed in the forefront. Tabbed pane is very common feature of GUI interfaces. It is commonly used in dialog boxes containing lots of commands. A tabbed pane is an object of JTabbedPane class.

Some of the constructors defined by JTabbedPane class are as follows:

JTabbedPane ()

JTabbedPane(int tabPlacement)


tabPlacement specifies the position of tabs-can have one of the four values: TOP, BOTTOM, LEFT or RIGHT


import java.awt.BorderLayout;

import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JTabbedPane;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.SwingConstants;
public class JavaExampleTabbedPane extends JFrame
    public JavaExampleTabbedPane()
               super("Example of Tab Pane in Java");
               JTabbedPane TbdPn = new JTabbedPane();
               JLabel LblOne = new JLabel("Panel One",SwingConstants.CENTER);
               JPanel PnlOne = new JPanel();
               TbdPn.addTab("Tab One",null,PnlOne,"First Panel");
               JLabel LblTwo = new JLabel("Panel Two",SwingConstants.CENTER);
               JPanel PnlTwo = new JPanel();
               TbdPn.addTab("Tab Two",null,PnlTwo,"Second Panel");
               JLabel LblThree = new JLabel("Panel Three");
               JPanel PnlThree = new JPanel();
               PnlThree.setLayout(new BorderLayout());
               PnlThree.add(new JButton("North"),BorderLayout.NORTH);
               PnlThree.add(new JButton("West"),BorderLayout.WEST);
               PnlThree.add(new JButton("East"),BorderLayout.EAST);
               PnlThree.add(new JButton("South"),BorderLayout.SOUTH);
               TbdPn.addTab("Tab Three",null,PnlThree,"Third panel");
                          public static void main(String aa[])
                           JavaExampleTabbedPane Frm = new JavaExampleTabbedPane();

JTabbedPane Java Example

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles