Java Reference
In-Depth Information
When using
addTab()
, the tab is added to the end, which is the farthest right position for a
set of top or bottom tabs, or at the very bottom for tabs positioned on the left or right side,
potentially reversing sides, depending on component orientation.
After creating a panel, you can change its title, icon, mnemonic, tooltip, or component on
a particular tab with one of the
set
XXX
At()
methods:
•
public void setTitleAt(int index, String title)
•
public void setIconAt(int index, Icon icon)
•
public void setMnemonicAt(int index, int mnemonic)
•
public void setDisplayedMnemonicIndexAt(int index, int mnemonicIndex)
•
public void setToolTipTextAt(int index, String text)
•
public void setComponentAt(int index, Component component)
■
Tip
The displayed mnemonic index refers to which time a particular character in the title should be high-
lighted. For instance, if you wanted the second
t
in
title
to be the highlighted mnemonic, you would set the
mnemonic character to
KeyEvent.VK_T
, with
setMnemonicAt()
, and the mnemonic index to be 2, with
setDisplayedMnemonicIndexAt()
.
In addition, you can change the background or foreground of a specific tab, enable or
disable a specific tab, or have a different disabled icon with additional
set
XXX
At()
methods:
•
public void setBackgroundAt(int index, Color background)
•
public void setForegroundAt(int index, Color foreground)
•
public void setEnabledAt(int index, boolean enabled)
•
public void setDisabledIconAt(int index, Icon disabledIcon)
To remove a tab, you can remove a specific tab with
removeTabAt(int index)
,
remove(int index)
, or
remove(Component component)
. In addition, you can remove all tabs
with
removeAll()
.
JTabbedPane Properties
Table 11-4 shows the 11 properties of
JTabbedPane
. Because many of the setter/getter methods of
JTabbedPane
specify an index parameter, they aren't true properties in the literal sense.