The JTabbedPane Class
The tabbed pane is now a fixture in applications for option displays, system configuration displays, and other multiscreen UIs. In the AWT, you have access to the CardLayout layout manager, which can be used to simulate the multiscreen behavior, but it contains nothing to graphically activate screen switching—you must write that yourself.
Here’s the code that generated this simple application. We use the tabbed pane as our real container and create new tabs using the addTab( ) method. Note that each tab can contain exactly one component. As with a CardLayout-managed container, you quite often add a container as the one component on the tab. That way, you can then add as many other components to the container as necessary.
import java.awt.*; import java.util.*; import java.awt.event.*; import javax.swing.*; public class SimpleTab extends JFrame { JTabbedPane jtp; public SimpleTab() { super("JTabbedPane"); setSize(200, 200); Container contents = getContentPane(); jtp = new JTabbedPane(); jtp.addTab("Tab1", new JLabel("This is Tab One")); jtp.addTab("Tab2", new JButton("This is Tab Two")); jtp.addTab("Tab3", new JCheckBox("This is Tab Three")); contents.add(jtp); setDefaultCloseOperation(EXIT_ON_CLOSE); setVisible(true); } public static void main(String args[]) { new SimpleTab(); } }