Java Reference
In-Depth Information
Table 18-8. DefaultTableColumnModel Properties
Property Name
Data Type
Access
columnCount
int
Read-only
columnMargin
int
Read-write
columnModelListeners
TableColumnModelListener[ ]
Read-only
columns
Enumeration
Read-only
columnSelectionAllowed
boolean
Read-write
selectedColumnCount
int
Read-only
selectedColumns
int[ ]
Read-only
selectionModel
ListSelectionModel
Read-write
totalColumnWidth
int
Read-only
In addition to the class properties, you can use the following methods to add, remove, and
move columns through the TableColumn class, which will be discussed shortly.
public void addColumn(TableColumn newColumn);
public void removeColumn(TableColumn oldColumn);
public void moveColumn(int currentIndex, int newIndex);
Listening to JTable Events with a TableColumnModelListener
One of the things you might want to do with a TableColumnModel is listen for
TableColumnModelEvent objects with a TableColumnModelListener . The listener will be notified
of any addition, removal, movement, or selection of columns, or changing of column margins,
as shown by the listener interface definition. Note that the different methods don't all receive
TableColumnModelEvent objects when the event happens.
public interface TableColumnModelListener extends EventListener {
public void columnAdded(TableColumnModelEvent e);
public void columnMarginChanged(ChangeEvent e);
public void columnMoved(TableColumnModelEvent e);
public void columnRemoved(TableColumnModelEvent e);
public void columnSelectionChanged(ListSelectionEvent e);
}
Because the listener definition identifies the event type, the TableColumnModelEvent definition
defines only the range of columns affected by the change, as shown in Table 18-9.
Table 18-9. TableColumnModelEvent Properties
Property Name
Data Type
Access
fromIndex
int
Read-only
toIndex
int
Read-only
 
Search WWH ::




Custom Search