Java: JTabbedPane

Description. The JTabbedPane container allows many panels to occupy the same area of the interface, and the user may select which to show by clicking on a tab. A tab may also be selected by the program.

Constructor

   JTabbedPane tp = new JTabbedPane();
   JTabbedPane tp = new JTabbedPane(edge);

Where edge specifies which edge the tabs are on

Adding tabs to the JTabbedPane

Add tabs to a tabbed pane by calling addTab and passing it a String title and a component (typically a JPanel) to display in that tab. For example,

JTabbedPane display = new JTabbedPane();
display.addTab("Diagram View", diagramPanel);
display.addTab("SQL View"    , sqlPanel);
display.addTab("Instructions", instructionPanel);

Selecting the tab to display

A tab can be selected by the program using setSelectedIndex().

display.setSelectedIndex(1);  // Display SQL View tab