DefaultTableColumnModel (Java SE 15 & JDK 15) (original) (raw)

Method Details

Appends aColumn to the end of thetableColumns array. This method also posts the columnAdded event to its listeners.
Specified by:
[addColumn](TableColumnModel.html#addColumn%28javax.swing.table.TableColumn%29) in interface [TableColumnModel](TableColumnModel.html "interface in javax.swing.table")
Parameters:
aColumn - the TableColumn to be added
Throws:
[IllegalArgumentException](../../../../java.base/java/lang/IllegalArgumentException.html "class in java.lang") - if aColumn isnull
See Also:
removeColumn(javax.swing.table.TableColumn)

public void removeColumn​(TableColumn column)
Deletes the column from thetableColumns array. This method will do nothing ifcolumn 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:
[removeColumn](TableColumnModel.html#removeColumn%28javax.swing.table.TableColumn%29) in interface [TableColumnModel](TableColumnModel.html "interface in javax.swing.table")
Parameters:
column - the TableColumn to be removed
See Also:
addColumn(javax.swing.table.TableColumn)

public void moveColumn​(int columnIndex, int newIndex)
Moves the column and heading at columnIndex tonewIndex. 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 ifcolumnIndex equals newIndex. This method also posts a columnMoved event to its listeners.
Specified by:
[moveColumn](TableColumnModel.html#moveColumn%28int,int%29) in interface [TableColumnModel](TableColumnModel.html "interface in javax.swing.table")
Parameters:
columnIndex - the index of column to be moved
newIndex - new index to move the column
Throws:
[IllegalArgumentException](../../../../java.base/java/lang/IllegalArgumentException.html "class in java.lang") - if column ornewIndex are not in the valid range

public void setColumnMargin​(int newMargin)
Sets the column margin to newMargin. This method also posts a columnMarginChanged event to its listeners.
Specified by:
[setColumnMargin](TableColumnModel.html#setColumnMargin%28int%29) in interface [TableColumnModel](TableColumnModel.html "interface in javax.swing.table")
Parameters:
newMargin - the new margin width, in pixels
See Also:
getColumnMargin(), getTotalColumnWidth()

public int getColumnCount()
Returns the number of columns in the tableColumns array.
Specified by:
[getColumnCount](TableColumnModel.html#getColumnCount%28%29) in interface [TableColumnModel](TableColumnModel.html "interface in javax.swing.table")
Returns:
the number of columns in the tableColumns array
See Also:
getColumns()

Returns an Enumeration of all the columns in the model.
Specified by:
[getColumns](TableColumnModel.html#getColumns%28%29) in interface [TableColumnModel](TableColumnModel.html "interface in javax.swing.table")
Returns:
an Enumeration of the columns in the model

public int getColumnIndex​(Object identifier)
Returns the index of the first column in the tableColumns array whose identifier is equal to identifier, when compared using equals.
Specified by:
[getColumnIndex](TableColumnModel.html#getColumnIndex%28java.lang.Object%29) in interface [TableColumnModel](TableColumnModel.html "interface in javax.swing.table")
Parameters:
identifier - the identifier object
Returns:
the index of the first column in thetableColumns array whose identifier is equal to identifier
Throws:
[IllegalArgumentException](../../../../java.base/java/lang/IllegalArgumentException.html "class in java.lang") - if identifier is null, or if noTableColumn has thisidentifier
See Also:
getColumn(int)

public TableColumn getColumn​(int columnIndex)
Returns the TableColumn object for the column at columnIndex.
Specified by:
[getColumn](TableColumnModel.html#getColumn%28int%29) in interface [TableColumnModel](TableColumnModel.html "interface in javax.swing.table")
Parameters:
columnIndex - the index of the column desired
Returns:
the TableColumn object for the column at columnIndex

public int getColumnMargin()
Returns the width margin for TableColumn. The default columnMargin is 1.
Specified by:
[getColumnMargin](TableColumnModel.html#getColumnMargin%28%29) in interface [TableColumnModel](TableColumnModel.html "interface in javax.swing.table")
Returns:
the maximum width for the TableColumn
See Also:
setColumnMargin(int)

public int getColumnIndexAtX​(int x)
Returns the index of the column that lies at position 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:
[getColumnIndexAtX](TableColumnModel.html#getColumnIndexAtX%28int%29) in interface [TableColumnModel](TableColumnModel.html "interface in javax.swing.table")
Parameters:
x - the horizontal location of interest
Returns:
the index of the column or -1 if no column is found
See Also:
JTable.columnAtPoint(java.awt.Point)

public int getTotalColumnWidth()
Returns the total combined width of all columns.
Specified by:
[getTotalColumnWidth](TableColumnModel.html#getTotalColumnWidth%28%29) in interface [TableColumnModel](TableColumnModel.html "interface in javax.swing.table")
Returns:
the totalColumnWidth property

Sets the selection model for this TableColumnModel to newModel and registers for listener notifications from the new selection model. If newModel is null, an exception is thrown.
Specified by:
[setSelectionModel](TableColumnModel.html#setSelectionModel%28javax.swing.ListSelectionModel%29) in interface [TableColumnModel](TableColumnModel.html "interface in javax.swing.table")
Parameters:
newModel - the new selection model
Throws:
[IllegalArgumentException](../../../../java.base/java/lang/IllegalArgumentException.html "class in java.lang") - if newModel is null
See Also:
getSelectionModel()

Returns the ListSelectionModel that is used to maintain column selection state.
Specified by:
[getSelectionModel](TableColumnModel.html#getSelectionModel%28%29) in interface [TableColumnModel](TableColumnModel.html "interface in javax.swing.table")
Returns:
the object that provides column selection state. Ornull if row selection is not allowed.
See Also:
setSelectionModel(javax.swing.ListSelectionModel)

public void setColumnSelectionAllowed​(boolean flag)
Sets whether column selection is allowed. The default is false.
Specified by:
[setColumnSelectionAllowed](TableColumnModel.html#setColumnSelectionAllowed%28boolean%29) in interface [TableColumnModel](TableColumnModel.html "interface in javax.swing.table")
Parameters:
flag - true if column selection will be allowed, false otherwise
See Also:
TableColumnModel.getColumnSelectionAllowed()

public boolean getColumnSelectionAllowed()
Returns true if column selection is allowed, otherwise false. The default is false.
Specified by:
[getColumnSelectionAllowed](TableColumnModel.html#getColumnSelectionAllowed%28%29) in interface [TableColumnModel](TableColumnModel.html "interface in javax.swing.table")
Returns:
the columnSelectionAllowed property
See Also:
TableColumnModel.setColumnSelectionAllowed(boolean)

public int[] getSelectedColumns()
Returns an array of selected columns. If selectionModel is null, returns an empty array.
Specified by:
[getSelectedColumns](TableColumnModel.html#getSelectedColumns%28%29) in interface [TableColumnModel](TableColumnModel.html "interface in javax.swing.table")
Returns:
an array of selected columns or an empty array if nothing is selected or the selectionModel isnull

public int getSelectedColumnCount()
Returns the number of columns selected.
Specified by:
[getSelectedColumnCount](TableColumnModel.html#getSelectedColumnCount%28%29) in interface [TableColumnModel](TableColumnModel.html "interface in javax.swing.table")
Returns:
the number of columns selected

Adds a listener for table column model events.
Specified by:
[addColumnModelListener](TableColumnModel.html#addColumnModelListener%28javax.swing.event.TableColumnModelListener%29) in interface [TableColumnModel](TableColumnModel.html "interface in javax.swing.table")
Parameters:
x - a TableColumnModelListener object

Removes a listener for table column model events.
Specified by:
[removeColumnModelListener](TableColumnModel.html#removeColumnModelListener%28javax.swing.event.TableColumnModelListener%29) in interface [TableColumnModel](TableColumnModel.html "interface in javax.swing.table")
Parameters:
x - a TableColumnModelListener object

Returns an array of all the column model listeners registered on this model.
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:
addColumnModelListener(javax.swing.event.TableColumnModelListener), removeColumnModelListener(javax.swing.event.TableColumnModelListener)

Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.
Parameters:
e - the event received
See Also:
EventListenerList

Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.
Parameters:
e - the event received
See Also:
EventListenerList

Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.
Parameters:
e - the event received
See Also:
EventListenerList

Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.
Parameters:
e - the event received
See Also:
EventListenerList

protected void fireColumnMarginChanged()
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.
See Also:
EventListenerList

public <T extends EventListener> T[] getListeners​(Class listenerType)
Returns an array of all the objects currently registered as _Foo_Listeners upon this model._Foo_Listeners are registered using theadd_Foo_Listener method.
You can specify the listenerType argument with a class literal, such as_Foo_Listener.class. For example, you can query aDefaultTableColumnModel 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_Foo_Listeners on this model, or an empty array if no such listeners have been added
Throws:
[ClassCastException](../../../../java.base/java/lang/ClassCastException.html "class in java.lang") - if listenerType doesn't specify a class or interface that implementsjava.util.EventListener
Since:
1.3
See Also:
getColumnModelListeners()

Property Change Listener change method. Used to track changes to the column width or preferred column width.
Specified by:
[propertyChange](../../../java/beans/PropertyChangeListener.html#propertyChange%28java.beans.PropertyChangeEvent%29) in interface [PropertyChangeListener](../../../java/beans/PropertyChangeListener.html "interface in java.beans")
Parameters:
evt - PropertyChangeEvent

A ListSelectionListener that forwardsListSelectionEvents when there is a column selection change.
Specified by:
[valueChanged](../event/ListSelectionListener.html#valueChanged%28javax.swing.event.ListSelectionEvent%29) in interface [ListSelectionListener](../event/ListSelectionListener.html "interface in javax.swing.event")
Parameters:
e - the change event

Creates a new default list selection model.
Returns:
a newly created default list selection model.

protected void recalcWidthCache()
Recalculates the total combined width of all columns. Updates thetotalColumnWidth property.