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.
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
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);
A tab can be selected by the program using setSelectedIndex()
.
display.setSelectedIndex(1); // Display SQL View tab