Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
javax.swing.table.DefaultTableColumnModel
public class DefaultTableColumnModel
extends Object
JTable
.
Field Summary | |
protected ChangeEvent |
|
protected int |
|
protected boolean |
|
protected EventListenerList |
|
protected ListSelectionModel |
|
protected Vector |
|
protected int |
|
Constructor Summary | |
|
Method Summary | |
void |
|
void |
|
protected ListSelectionModel |
|
|
|
protected void |
|
protected void |
|
protected void |
|
protected void |
|
protected void |
|
TableColumn |
|
int |
|
int |
|
int |
|
int |
|
TableColumnModelListener[] |
|
boolean |
|
Enumeration |
|
int |
|
int[] |
|
ListSelectionModel |
|
int |
|
void |
|
void |
|
protected void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
Methods inherited from class java.lang.Object | |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
protected ChangeEvent changeEvent
A change event used when notifying listeners of a change to thecolumnMargin
field. This single event is reused for all notifications (it is lazily instantiated within thefireColumnMarginChanged()
method).
protected boolean columnSelectionAllowed
A flag that indicates whether or not columns can be selected.
protected EventListenerList listenerList
Storage for the listeners registered with the model.
protected ListSelectionModel selectionModel
A selection model that keeps track of column selections.
public DefaultTableColumnModel()
Creates a new table column model with zero columns. A default column selection model is created by callingcreateSelectionModel()
. The default value forcolumnMargin
is1
and the default value forcolumnSelectionAllowed
isfalse
.
public void addColumn(TableColumn column)
Adds a column to the model then callsfireColumnAdded(TableColumnModelEvent)
to notify the registered listeners. The model registers itself with the column as aPropertyChangeListener
so that changes to the column width will invalidate the cachedtotalColumnWidth
value.
- Specified by:
- addColumn in interface TableColumnModel
- Parameters:
column
- the column (null
not permitted).
- Throws:
IllegalArgumentException
- ifcolumn
isnull
.
- See Also:
removeColumn(TableColumn)
public void addColumnModelListener(TableColumnModelListener listener)
Registers a listener with the model, so that it will receiveTableColumnModelEvent
notifications.
- Specified by:
- addColumnModelListener in interface TableColumnModel
- Parameters:
listener
- the listener (null
ignored).
protected ListSelectionModel createSelectionModel()
Creates a default selection model to track the currently selected column(s). This method is called by the constructor and returns a new instance ofDefaultListSelectionModel
.
- Returns:
- A new default column selection model.
publicextends EventListener> T[] getListeners (ClasslistenerType)
Returns an array containing the listeners (of the specified type) that are registered with this model.
- Parameters:
listenerType
- the listener type (must indicate a subclass ofEventListener
,null
not permitted).
- Returns:
- An array containing the listeners (of the specified type) that are registered with this model.
protected void fireColumnAdded(TableColumnModelEvent e)
Sends the specifiedTableColumnModelEvent
to all registered listeners, to indicate that a column has been added to the model. The event'stoIndex
attribute should contain the index of the added column.
- Parameters:
e
- the event.
- See Also:
addColumn(TableColumn)
protected void fireColumnMarginChanged()
Sends aChangeEvent
to the model's registered listeners to indicate that the column margin was changed.
- See Also:
setColumnMargin(int)
protected void fireColumnMoved(TableColumnModelEvent e)
Sends the specifiedTableColumnModelEvent
to all registered listeners, to indicate that a column in the model has been moved. The event'sfromIndex
attribute should contain the old column index, and thetoIndex
attribute should contain the new column index.
- Parameters:
e
- the event.
- See Also:
moveColumn(int,int)
protected void fireColumnRemoved(TableColumnModelEvent e)
Sends the specifiedTableColumnModelEvent
to all registered listeners, to indicate that a column has been removed from the model. The event'sfromIndex
attribute should contain the index of the removed column.
- Parameters:
e
- the event.
- See Also:
removeColumn(TableColumn)
protected void fireColumnSelectionChanged(ListSelectionEvent e)
Sends the specifiedListSelectionEvent
to all registered listeners, to indicate that the column selections have changed.
- Parameters:
e
- the event.
- See Also:
valueChanged(ListSelectionEvent)
public TableColumn getColumn(int columnIndex)
Returns the column at the specified index.
- Specified by:
- getColumn in interface TableColumnModel
- Parameters:
columnIndex
- the column index (in the range from0
toN-1
, whereN
is the number of columns in the model).
- Returns:
- The column at the specified index.
- Throws:
ArrayIndexOutOfBoundsException
- ifi
is not within the specified range.
public int getColumnCount()
Returns the number of columns in the model.
- Specified by:
- getColumnCount in interface TableColumnModel
- Returns:
- The column count.
public int getColumnIndex(Object identifier)
Returns the index of theTableColumn
with the given identifier.
- Specified by:
- getColumnIndex in interface TableColumnModel
- Parameters:
identifier
- the identifier (null
not permitted).
- Returns:
- The index of the
TableColumn
with the given identifier.
- Throws:
IllegalArgumentException
- ifidentifier
isnull
or there is no column with that identifier.
public int getColumnIndexAtX(int x)
Returns the index of the column that contains the specified x-coordinate. This method assumes that:If no column contains the specified position, this method returns
- column zero begins at position zero;
- all columns appear in order;
- individual column widths are taken into account, but the column margin is ignored.
-1
.
- Specified by:
- getColumnIndexAtX in interface TableColumnModel
- Parameters:
x
- the x-position.
- Returns:
- The column index, or
-1
.
public int getColumnMargin()
Returns the column margin.
- Specified by:
- getColumnMargin in interface TableColumnModel
- Returns:
- The column margin.
- See Also:
setColumnMargin(int)
public TableColumnModelListener[] getColumnModelListeners()
Returns an array containing the listeners that are registered with the model. If there are no listeners, an empty array is returned.
- Returns:
- An array containing the listeners that are registered with the model.
- Since:
- 1.4
public boolean getColumnSelectionAllowed()
Returnstrue
if column selection is allowed, andfalse
if column selection is not allowed.
- Specified by:
- getColumnSelectionAllowed in interface TableColumnModel
- Returns:
- A boolean.
- See Also:
setColumnSelectionAllowed(boolean)
public EnumerationgetColumns()
Returns an enumeration of the columns in the model.
- Specified by:
- getColumns in interface TableColumnModel
- Returns:
- An enumeration of the columns in the model.
public int getSelectedColumnCount()
Returns the number of selected columns in the model.
- Specified by:
- getSelectedColumnCount in interface TableColumnModel
- Returns:
- The selected column count.
- See Also:
getSelectionModel()
public int[] getSelectedColumns()
Returns an array containing the indices of the selected columns.
- Specified by:
- getSelectedColumns in interface TableColumnModel
- Returns:
- An array containing the indices of the selected columns.
public ListSelectionModel getSelectionModel()
Returns the selection model used to track table column selections.
- Specified by:
- getSelectionModel in interface TableColumnModel
- Returns:
- The selection model.
public int getTotalColumnWidth()
Returns total width of all the columns in the model, ignoring thecolumnMargin
.
- Specified by:
- getTotalColumnWidth in interface TableColumnModel
- Returns:
- The total width of all the columns.
public void moveColumn(int i, int j)
Moves the column at index i to the position specified by index j, then callsfireColumnMoved(TableColumnModelEvent)
to notify registered listeners.
- Specified by:
- moveColumn in interface TableColumnModel
- Parameters:
i
- index of the column that will be moved.j
- index of the column's new location.
- Throws:
IllegalArgumentException
- ifi
orj
are outside the range0
toN-1
, whereN
is the column count.
public void propertyChange(PropertyChangeEvent event)
Receives notification of property changes for the columns in the model. If thewidth
property for any column changes, we invalidate thetotalColumnWidth
value here.
- Specified by:
- propertyChange in interface PropertyChangeListener
- Parameters:
event
- the event.
protected void recalcWidthCache()
Recalculates the total width of the columns, if the cached value is-1
. Otherwise this method does nothing.
- See Also:
getTotalColumnWidth()
public void removeColumn(TableColumn column)
Removes a column from the model then callsfireColumnRemoved(TableColumnModelEvent)
to notify the registered listeners. If the specified column does not belong to the model, or isnull
, this method does nothing.
- Specified by:
- removeColumn in interface TableColumnModel
- Parameters:
column
- the column to be removed (null
permitted).
- See Also:
addColumn(TableColumn)
public void removeColumnModelListener(TableColumnModelListener listener)
Deregisters a listener so that it no longer receives notification of changes to this model.
- Specified by:
- removeColumnModelListener in interface TableColumnModel
- Parameters:
listener
- the listener to remove
public void setColumnMargin(int margin)
Sets the column margin then callsfireColumnMarginChanged()
to notify the registered listeners.
- Specified by:
- setColumnMargin in interface TableColumnModel
- Parameters:
margin
- the column margin.
- See Also:
getColumnMargin()
public void setColumnSelectionAllowed(boolean flag)
Sets the flag that indicates whether or not column selection is allowed.
- Specified by:
- setColumnSelectionAllowed in interface TableColumnModel
- Parameters:
flag
- the new flag value.
- See Also:
getColumnSelectionAllowed()
public void setSelectionModel(ListSelectionModel model)
Sets the selection model that will be used to keep track of the selected columns.
- Specified by:
- setSelectionModel in interface TableColumnModel
- Parameters:
model
- the selection model (null
not permitted).
- Throws:
IllegalArgumentException
- ifmodel
isnull
.
- See Also:
getSelectionModel()
public void valueChanged(ListSelectionEvent e)
Receives notification of the change to the list selection model, and responds by callingfireColumnSelectionChanged(ListSelectionEvent)
.
- Specified by:
- valueChanged in interface ListSelectionListener
- Parameters:
e
- the list selection event.
- See Also:
getSelectionModel()