Java Reference
In-Depth Information
the JList component information in Chapter 13. They're used to describe the current set of
rows and columns within the JTable component. They have three settings:
MULTIPLE_INTERVAL_SELECTION (the default)
• SINGLE_INTERVAL_SELECTION
• SINGLE_SELECTION
The JTable has independent selection models for both rows and columns. The row selection
model is stored with the selectionModel property of the JTable . The column selection model is
stored with the TableColumnModel . Setting the selectionMode property of a JTable sets the selection
mode for the two independent selection models of the JTable .
Once a selection mode has been set and a user interacts with the component, you can ask
the selection model what happened, or, more precisely, what the user has selected. Table 18-2
lists the properties available to facilitate selection with the DefaultListSelectionModel .
Table 18-2. DefaultListSelectionModel Properties
Property Name
Data Type
Access
anchorSelectionIndex
int
Read-write
leadAnchorNotificationEnabled
boolean
Read-write
leadSelectionIndex
int
Read-write
listSelectionListeners
ListSelectionListener[ ]
Read-only
maxSelectionIndex
int
Read-only
minSelectionIndex
int
Read-only
selectionEmpty
boolean
Read-only
selectionModel
int
Read-write
valueIsAdjusting
boolean
Read-write
If you're interested in knowing when a selection event happens, register a
ListSelectionListener with the ListSelectionModel . The ListSelectionListener was
demonstrated in Chapter 13 with the JList component.
Note All table indices are zero-based. So, the first visual column is column 0 internally.
Auto-Resize Modes
The last subset of the JTable properties deals with the column-resize behavior of the JTable .
When the JTable is in a column or window that changes sizes, how does it react? Table 18-3
shows the five settings supported by a JTable .
 
Search WWH ::




Custom Search