Class DefaultTableColumnModel
- All Implemented Interfaces:
-
PropertyChangeListener,Serializable,EventListener,ListSelectionListener,TableColumnModel
public class DefaultTableColumnModel extends Object implements TableColumnModel, PropertyChangeListener, ListSelectionListener, Serializable
JTable. Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeans has been added to the java.beans package. Please see XMLEncoder.
- See Also:
Field Summary
| Modifier and Type | Field | Description |
|---|---|---|
protected ChangeEvent |
changeEvent |
Change event (only one needed) |
protected int |
columnMargin |
Width margin between each column |
protected boolean |
columnSelectionAllowed |
Column selection allowed in this column model |
protected EventListenerList |
listenerList |
List of TableColumnModelListener |
protected ListSelectionModel |
selectionModel |
Model for keeping track of column selections |
protected Vector<TableColumn> |
tableColumns |
Array of TableColumn objects in this model |
protected int |
totalColumnWidth |
A local cache of the combined width of all columns |
Constructor Summary
| Constructor | Description |
|---|---|
DefaultTableColumnModel() |
Creates a default table column model. |
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
void |
addColumn |
Appends aColumn to the end of the tableColumns array. |
void |
addColumnModelListener |
Adds a listener for table column model events. |
protected ListSelectionModel |
createSelectionModel() |
Creates a new default list selection model. |
protected void |
fireColumnAdded |
Notifies all listeners that have registered interest for notification on this event type. |
protected void |
fireColumnMarginChanged() |
Notifies all listeners that have registered interest for notification on this event type. |
protected void |
fireColumnMoved |
Notifies all listeners that have registered interest for notification on this event type. |
protected void |
fireColumnRemoved |
Notifies all listeners that have registered interest for notification on this event type. |
protected void |
fireColumnSelectionChanged |
Notifies all listeners that have registered interest for notification on this event type. |
TableColumn |
getColumn |
Returns the TableColumn object for the column at columnIndex. |
int |
getColumnCount() |
Returns the number of columns in the tableColumns array. |
int |
getColumnIndex |
Returns the index of the first column in the tableColumns array whose identifier is equal to identifier, when compared using equals. |
int |
getColumnIndexAtX |
Returns the index of the column that lies at position x, or -1 if no column covers this point. |
int |
getColumnMargin() |
Returns the width margin for TableColumn. |
TableColumnModelListener[] |
getColumnModelListeners() |
Returns an array of all the column model listeners registered on this model. |
Enumeration<TableColumn> |
getColumns() |
Returns an Enumeration of all the columns in the model. |
boolean |
getColumnSelectionAllowed() |
Returns true if column selection is allowed, otherwise false. |
<T extends EventListener> |
getListeners |
Returns an array of all the objects currently registered as FooListeners upon this model. |
int |
getSelectedColumnCount() |
Returns the number of columns selected. |
int[] |
getSelectedColumns() |
Returns an array of selected columns. |
ListSelectionModel |
getSelectionModel() |
Returns the ListSelectionModel that is used to maintain column selection state. |
int |
getTotalColumnWidth() |
Returns the total combined width of all columns. |
void |
moveColumn |
Moves the column and heading at columnIndex to newIndex. |
void |
propertyChange |
Property Change Listener change method. |
protected void |
recalcWidthCache() |
Recalculates the total combined width of all columns. |
void |
removeColumn |
Deletes the column from the tableColumns array. |
void |
removeColumnModelListener |
Removes a listener for table column model events. |
void |
setColumnMargin |
Sets the column margin to newMargin. |
void |
setColumnSelectionAllowed |
Sets whether column selection is allowed. |
void |
setSelectionModel |
Sets the selection model for this TableColumnModel to newModel and registers for listener notifications from the new selection model. |
void |
valueChanged |
A ListSelectionListener that forwards ListSelectionEvents when there is a column selection change. |
Field Details
tableColumns
protected Vector<TableColumn> tableColumns
selectionModel
protected ListSelectionModel selectionModel
columnMargin
protected int columnMargin
listenerList
protected EventListenerList listenerList
changeEvent
protected transient ChangeEvent changeEvent
columnSelectionAllowed
protected boolean columnSelectionAllowed
totalColumnWidth
protected int totalColumnWidth
Constructor Details
DefaultTableColumnModel
public DefaultTableColumnModel()
Method Details
addColumn
public void addColumn(TableColumn aColumn)
aColumn to the end of the tableColumns array. This method also posts the columnAdded event to its listeners.- Specified by:
-
addColumnin interfaceTableColumnModel - Parameters:
-
aColumn- theTableColumnto be added - Throws:
-
IllegalArgumentException- ifaColumnisnull - See Also:
removeColumn
public void removeColumn(TableColumn column)
column from the tableColumns array. This method will do nothing if column is not in the table's columns list. tile is called to resize both the header and table views. This method also posts a columnRemoved event to its listeners.- Specified by:
-
removeColumnin interfaceTableColumnModel - Parameters:
-
column- theTableColumnto be removed - See Also:
moveColumn
public void moveColumn(int columnIndex, int newIndex)
columnIndex to newIndex. The old column at columnIndex will now be found at newIndex. The column that used to be at newIndex is shifted left or right to make room. This will not move any columns if columnIndex equals newIndex. This method also posts a columnMoved event to its listeners.- Specified by:
-
moveColumnin interfaceTableColumnModel - Parameters:
-
columnIndex- the index of column to be moved -
newIndex- new index to move the column - Throws:
-
IllegalArgumentException- ifcolumnornewIndexare not in the valid range
setColumnMargin
public void setColumnMargin(int newMargin)
newMargin. This method also posts a columnMarginChanged event to its listeners.- Specified by:
-
setColumnMarginin interfaceTableColumnModel - Parameters:
-
newMargin- the new margin width, in pixels - See Also:
getColumnCount
public int getColumnCount()
tableColumns array.- Specified by:
-
getColumnCountin interfaceTableColumnModel - Returns:
- the number of columns in the
tableColumnsarray - See Also:
getColumns
public Enumeration<TableColumn> getColumns()
Enumeration of all the columns in the model.- Specified by:
-
getColumnsin interfaceTableColumnModel - Returns:
- an
Enumerationof the columns in the model
getColumnIndex
public int getColumnIndex(Object identifier)
tableColumns array whose identifier is equal to identifier, when compared using equals.- Specified by:
-
getColumnIndexin interfaceTableColumnModel - Parameters:
-
identifier- the identifier object - Returns:
- the index of the first column in the
tableColumnsarray whose identifier is equal toidentifier - Throws:
-
IllegalArgumentException- ifidentifierisnull, or if noTableColumnhas thisidentifier - See Also:
getColumn
public TableColumn getColumn(int columnIndex)
TableColumn object for the column at columnIndex.- Specified by:
-
getColumnin interfaceTableColumnModel - Parameters:
-
columnIndex- the index of the column desired - Returns:
- the
TableColumnobject for the column atcolumnIndex
getColumnMargin
public int getColumnMargin()
TableColumn. The default columnMargin is 1.- Specified by:
-
getColumnMarginin interfaceTableColumnModel - Returns:
- the maximum width for the
TableColumn - See Also:
getColumnIndexAtX
public int getColumnIndexAtX(int x)
x, or -1 if no column covers this point. In keeping with Swing's separable model architecture, a TableColumnModel does not know how the table columns actually appear on screen. The visual presentation of the columns is the responsibility of the view/controller object using this model (typically JTable). The view/controller need not display the columns sequentially from left to right. For example, columns could be displayed from right to left to accommodate a locale preference or some columns might be hidden at the request of the user. Because the model does not know how the columns are laid out on screen, the given xPosition should not be considered to be a coordinate in 2D graphics space. Instead, it should be considered to be a width from the start of the first column in the model. If the column index for a given X coordinate in 2D space is required, JTable.columnAtPoint can be used instead.- Specified by:
-
getColumnIndexAtXin interfaceTableColumnModel - Parameters:
-
x- the horizontal location of interest - Returns:
- the index of the column or -1 if no column is found
- See Also:
getTotalColumnWidth
public int getTotalColumnWidth()
- Specified by:
-
getTotalColumnWidthin interfaceTableColumnModel - Returns:
- the
totalColumnWidthproperty
setSelectionModel
public void setSelectionModel(ListSelectionModel newModel)
TableColumnModel to newModel and registers for listener notifications from the new selection model. If newModel is null, an exception is thrown.- Specified by:
-
setSelectionModelin interfaceTableColumnModel - Parameters:
-
newModel- the new selection model - Throws:
-
IllegalArgumentException- ifnewModelisnull - See Also:
getSelectionModel
public ListSelectionModel getSelectionModel()
ListSelectionModel that is used to maintain column selection state.- Specified by:
-
getSelectionModelin interfaceTableColumnModel - Returns:
- the object that provides column selection state. Or
nullif row selection is not allowed. - See Also:
setColumnSelectionAllowed
public void setColumnSelectionAllowed(boolean flag)
- Specified by:
-
setColumnSelectionAllowedin interfaceTableColumnModel - Parameters:
-
flag- true if column selection will be allowed, false otherwise - See Also:
getColumnSelectionAllowed
public boolean getColumnSelectionAllowed()
- Specified by:
-
getColumnSelectionAllowedin interfaceTableColumnModel - Returns:
- the
columnSelectionAllowedproperty - See Also:
getSelectedColumns
public int[] getSelectedColumns()
selectionModel is null, returns an empty array.- Specified by:
-
getSelectedColumnsin interfaceTableColumnModel - Returns:
- an array of selected columns or an empty array if nothing is selected or the
selectionModelisnull
getSelectedColumnCount
public int getSelectedColumnCount()
- Specified by:
-
getSelectedColumnCountin interfaceTableColumnModel - Returns:
- the number of columns selected
addColumnModelListener
public void addColumnModelListener(TableColumnModelListener x)
- Specified by:
-
addColumnModelListenerin interfaceTableColumnModel - Parameters:
-
x- aTableColumnModelListenerobject
removeColumnModelListener
public void removeColumnModelListener(TableColumnModelListener x)
- Specified by:
-
removeColumnModelListenerin interfaceTableColumnModel - Parameters:
-
x- aTableColumnModelListenerobject
getColumnModelListeners
public TableColumnModelListener[] getColumnModelListeners()
- Returns:
- all of this default table column model's
ColumnModelListeners or an empty array if no column model listeners are currently registered - Since:
- 1.4
- See Also:
fireColumnAdded
protected void fireColumnAdded(TableColumnModelEvent e)
- Parameters:
-
e- the event received - See Also:
fireColumnRemoved
protected void fireColumnRemoved(TableColumnModelEvent e)
- Parameters:
-
e- the event received - See Also:
fireColumnMoved
protected void fireColumnMoved(TableColumnModelEvent e)
- Parameters:
-
e- the event received - See Also:
fireColumnSelectionChanged
protected void fireColumnSelectionChanged(ListSelectionEvent e)
- Parameters:
-
e- the event received - See Also:
fireColumnMarginChanged
protected void fireColumnMarginChanged()
- See Also:
getListeners
public <T extends EventListener> T[] getListeners(Class<T> listenerType)
FooListeners upon this model. FooListeners are registered using the addFooListener method. You can specify the listenerType argument with a class literal, such as FooListener.class. For example, you can query a DefaultTableColumnModel m for its column model listeners with the following code:
ColumnModelListener[] cmls = (ColumnModelListener[])(m.getListeners(ColumnModelListener.class));If no such listeners exist, this method returns an empty array.
- Type Parameters:
-
T- the listener type - Parameters:
-
listenerType- the type of listeners requested - Returns:
- an array of all objects registered as
FooListeners on this model, or an empty array if no such listeners have been added - Throws:
-
ClassCastException- iflistenerTypedoesn't specify a class or interface that implementsjava.util.EventListener - Since:
- 1.3
- See Also:
propertyChange
public void propertyChange(PropertyChangeEvent evt)
- Specified by:
-
propertyChangein interfacePropertyChangeListener - Parameters:
-
evt-PropertyChangeEvent
valueChanged
public void valueChanged(ListSelectionEvent e)
ListSelectionListener that forwards ListSelectionEvents when there is a column selection change.- Specified by:
-
valueChangedin interfaceListSelectionListener - Parameters:
-
e- the change event
createSelectionModel
protected ListSelectionModel createSelectionModel()
- Returns:
- a newly created default list selection model.
recalcWidthCache
protected void recalcWidthCache()
totalColumnWidth property.
© 1993, 2021, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/javax/swing/table/DefaultTableColumnModel.html