Java Reference
In-Depth Information
Figure 11-12.
JTabbedPane with the scroll tab layout
Adding and Removing Tabs
Once you've created the basic
JTabbedPane
container, you need to add panels that make up the
sheets or pages of the
JTabbedPane
. You can add panels in either one of two basic ways.
If you're visually creating your interface with a tool like JBuilder or Eclipse, the user inter-
face builder will use the familiar
add()
methods of
Container
to add a
Component
as a panel. The
panel added uses
component.getName()
as the default title. However, you shouldn't use the various
add()
methods if you're programming by hand.
The more appropriate way to add components or panels to create tabs is with any of the
addTab()
or
insertTab()
methods listed next. Any or all of the arguments other than the
component and the position index of
insertTab()
can be
null
. (Passing
null
as the
Component
argument causes a
NullPointerException
to be thrown at runtime.) The displayed icon and
tooltip settings have no default values.
•
public void addTab(String title, Component component)
•
public void addTab(String title, Icon icon, Component component)
•
public void addTab(String title, Icon icon, Component component, String tip)
•
public void insertTab(String title, Icon icon, Component component, String tip,
int index)