Java Reference
In-Depth Information
Table 11-4. JTabbedPane Properties
Property Name
Data Type
Access
accessibleContext
AccessibleContext
Read-only
changeListeners
ChangeListener[ ]
Read-only
model
SingleSelectionModel
Read-write bound
selectedComponent
Component
Read-write
selectedIndex
int
Read-write
tabCount
int
Read-only
tabLayoutPolicy
int
Read-write-bound
tabPlacement
int
Read-write bound
tabRunCount
int
Read-only
UI
TabbedPaneUI
Read-write bound
UIClassID
String
Read-only
You can programmatically change the displayed tab by setting either the selectedComponent or
the selectedIndex property.
The tabRunCount property represents the number of rows (for top or bottom tab placement)
or columns (for right or left placement) necessary to display all the tabs.
Caution Changing the LayoutManager for the JTabbedPane will throw an exception when it comes
time to displaying the container. In other words, don't do it.
Listening for Changing Tab Selection
If you're interested in finding out when the selected tab changes, you need to listen for changes
to the selection model. This is done by your attaching a ChangeListener to the JTabbedPane (or
directly to the SingleSelectionModel ). The registered ChangeListener reports when the selection
model changes, as the model changes when the selected panel changes.
The program shown in Listing 11-3 demonstrates listening for changes to the selected tab
and displays the title of the newly selected tab.
 
Search WWH ::




Custom Search