# 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

- `JTabbedPane.TOP` (default)
- `JTabbedPane.RIGHT`
- `JTabbedPane.BOTTOM`
- `JTabbedPane.LEFT`

## 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