Top Description Fields Constructors Methods
javax.swing.table

public Class DefaultTableColumnModel

extends Object
implements TableColumnModel, PropertyChangeListener, ListSelectionListener, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, javax.swing.event.ListSelectionListener, java.util.EventListener, java.beans.PropertyChangeListener, javax.swing.table.TableColumnModel
Annotations
@SuppressWarnings:serial
Imports
javax.swing.*, javax.swing.event.*, java.awt.*, java.util.Vector, .Enumeration, .EventListener, java.beans.PropertyChangeListener, .PropertyChangeEvent, java.io.Serializable, sun.swing.SwingUtilities2

The standard column-handler for a 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 java.beans.XMLEncoder.

Authors
Alan Chung, Philip Milne
See Also
JTable

Field Summary

Modifier and TypeField and Description
protected transient 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

AccessConstructor and Description
public
DefaultTableColumnModel()

Creates a default table column model.

Method Summary

Modifier and TypeMethod and Description
public void
addColumn(TableColumn
the TableColumn to be added
aColumn
)

Implements javax.swing.table.TableColumnModel.addColumn.

Appends aColumn to the end of the tableColumns array.

public void
addColumnModelListener(TableColumnModelListener
a TableColumnModelListener object
x
)

Implements javax.swing.table.TableColumnModel.addColumnModelListener.

Adds a listener for table column model events.

protected ListSelectionModel

Returns:

a newly created default list selection model.
createSelectionModel
()

Creates a new default list selection model.

protected void
fireColumnAdded(TableColumnModelEvent
the event received
e
)

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(TableColumnModelEvent
the event received
e
)

Notifies all listeners that have registered interest for notification on this event type.

protected void
fireColumnRemoved(TableColumnModelEvent
the event received
e
)

Notifies all listeners that have registered interest for notification on this event type.

protected void
fireColumnSelectionChanged(ListSelectionEvent
the event received
e
)

Notifies all listeners that have registered interest for notification on this event type.

public TableColumn

Returns:

the TableColumn object for the column at columnIndex
getColumn
(int
the index of the column desired
columnIndex
)

Implements javax.swing.table.TableColumnModel.getColumn.

Returns the TableColumn object for the column at columnIndex.

public int

Returns:

the number of columns in the tableColumns array
getColumnCount
()

Implements javax.swing.table.TableColumnModel.getColumnCount.

Returns the number of columns in the tableColumns array.

public int

Returns:

the index of the first column in the tableColumns array whose identifier is equal to identifier
getColumnIndex
(Object
the identifier object
identifier
)

Implements javax.swing.table.TableColumnModel.getColumnIndex.

Returns the index of the first column in the tableColumns array whose identifier is equal to identifier, when compared using equals.

public int

Returns:

the index of the column or -1 if no column is found
getColumnIndexAtX
(int
the horizontal location of interest
x
)

Implements javax.swing.table.TableColumnModel.getColumnIndexAtX.

Returns the index of the column that lies at position x, or -1 if no column covers this point.

public int

Returns:

the maximum width for the TableColumn
getColumnMargin
()

Implements javax.swing.table.TableColumnModel.getColumnMargin.

Returns the width margin for TableColumn.

public TableColumnModelListener[]

Returns:

all of this default table column model's ColumnModelListeners or an empty array if no column model listeners are currently registered
getColumnModelListeners
()

Returns an array of all the column model listeners registered on this model.

public Enumeration<TableColumn>

Returns:

an Enumeration of the columns in the model
getColumns
()

Implements javax.swing.table.TableColumnModel.getColumns.

Returns an Enumeration of all the columns in the model.

public boolean

Returns:

the columnSelectionAllowed property
getColumnSelectionAllowed
()

Implements javax.swing.table.TableColumnModel.getColumnSelectionAllowed.

Returns true if column selection is allowed, otherwise false.

public <
the listener type
T extends EventListener
>
T[]

Returns:

an array of all objects registered as FooListeners on this model, or an empty array if no such listeners have been added
getListeners
(Class<T>
the type of listeners requested
listenerType
)

Returns an array of all the objects currently registered as FooListeners upon this model.

public int

Returns:

the number of columns selected
getSelectedColumnCount
()

Implements javax.swing.table.TableColumnModel.getSelectedColumnCount.

Returns the number of columns selected.

public int[]

Returns:

an array of selected columns or an empty array if nothing is selected or the selectionModel is null
getSelectedColumns
()

Implements javax.swing.table.TableColumnModel.getSelectedColumns.

Returns an array of selected columns.

public ListSelectionModel

Returns:

the object that provides column selection state. Or null if row selection is not allowed.
getSelectionModel
()

Implements javax.swing.table.TableColumnModel.getSelectionModel.

Returns the ListSelectionModel that is used to maintain column selection state.

public int

Returns:

the totalColumnWidth property
getTotalColumnWidth
()

Implements javax.swing.table.TableColumnModel.getTotalColumnWidth.

Returns the total combined width of all columns.

private void
public void
moveColumn(int
the index of column to be moved
columnIndex
,
int
new index to move the column
newIndex
)

Implements javax.swing.table.TableColumnModel.moveColumn.

Moves the column and heading at columnIndex to newIndex.

public void
propertyChange(PropertyChangeEvent
PropertyChangeEvent
evt
)

Implements java.beans.PropertyChangeListener.propertyChange.

Property Change Listener change method.

protected void
recalcWidthCache()

Recalculates the total combined width of all columns.

public void
removeColumn(TableColumn
the TableColumn to be removed
column
)

Implements javax.swing.table.TableColumnModel.removeColumn.

Deletes the column from the tableColumns array.

public void
removeColumnModelListener(TableColumnModelListener
a TableColumnModelListener object
x
)

Implements javax.swing.table.TableColumnModel.removeColumnModelListener.

Removes a listener for table column model events.

public void
setColumnMargin(int
the new margin width, in pixels
newMargin
)

Implements javax.swing.table.TableColumnModel.setColumnMargin.

Sets the column margin to newMargin.

public void
setColumnSelectionAllowed(boolean
true if column selection will be allowed, false otherwise
flag
)

Implements javax.swing.table.TableColumnModel.setColumnSelectionAllowed.

Sets whether column selection is allowed.

public void
setSelectionModel(ListSelectionModel
the new selection model
newModel
)

Implements javax.swing.table.TableColumnModel.setSelectionModel.

Sets the selection model for this TableColumnModel to newModel and registers for listener notifications from the new selection model.

public void
valueChanged(ListSelectionEvent
the change event
e
)

Implements javax.swing.event.ListSelectionListener.valueChanged.

A ListSelectionListener that forwards ListSelectionEvents when there is a column selection change.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

changeEventback to summary
protected transient ChangeEvent changeEvent

Change event (only one needed)

columnMarginback to summary
protected int columnMargin

Width margin between each column

columnSelectionAllowedback to summary
protected boolean columnSelectionAllowed

Column selection allowed in this column model

listenerListback to summary
protected EventListenerList listenerList

List of TableColumnModelListener

selectionModelback to summary
protected ListSelectionModel selectionModel

Model for keeping track of column selections

tableColumnsback to summary
protected Vector<TableColumn> tableColumns

Array of TableColumn objects in this model

totalColumnWidthback to summary
protected int totalColumnWidth

A local cache of the combined width of all columns

Constructor Detail

DefaultTableColumnModelback to summary
public DefaultTableColumnModel()

Creates a default table column model.

Method Detail

addColumnback to summary
public void addColumn(TableColumn aColumn)

Implements javax.swing.table.TableColumnModel.addColumn.

Appends aColumn to the end of the tableColumns array. This method also posts the columnAdded event to its listeners.

Parameters
aColumn:TableColumn

the TableColumn to be added

Exceptions
IllegalArgumentException:
if aColumn is null
See Also
removeColumn
addColumnModelListenerback to summary
public void addColumnModelListener(TableColumnModelListener x)

Implements javax.swing.table.TableColumnModel.addColumnModelListener.

Adds a listener for table column model events.

Parameters
x:TableColumnModelListener

a TableColumnModelListener object

createSelectionModelback to summary
protected ListSelectionModel createSelectionModel()

Creates a new default list selection model.

Returns:ListSelectionModel

a newly created default list selection model.

fireColumnAddedback to summary
protected void fireColumnAdded(TableColumnModelEvent e)

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:TableColumnModelEvent

the event received

See Also
EventListenerList
fireColumnMarginChangedback to summary
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
fireColumnMovedback to summary
protected void fireColumnMoved(TableColumnModelEvent e)

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:TableColumnModelEvent

the event received

See Also
EventListenerList
fireColumnRemovedback to summary
protected void fireColumnRemoved(TableColumnModelEvent e)

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:TableColumnModelEvent

the event received

See Also
EventListenerList
fireColumnSelectionChangedback to summary
protected void fireColumnSelectionChanged(ListSelectionEvent e)

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:ListSelectionEvent

the event received

See Also
EventListenerList
getColumnback to summary
public TableColumn getColumn(int columnIndex)

Implements javax.swing.table.TableColumnModel.getColumn.

Returns the TableColumn object for the column at columnIndex.

Parameters
columnIndex:int

the index of the column desired

Returns:TableColumn

the TableColumn object for the column at columnIndex

Exceptions
ArrayIndexOutOfBoundsException:
if columnIndex is out of range: (columnIndex < 0 || columnIndex >= getColumnCount())
getColumnCountback to summary
public int getColumnCount()

Implements javax.swing.table.TableColumnModel.getColumnCount.

Returns the number of columns in the tableColumns array.

Returns:int

the number of columns in the tableColumns array

See Also
getColumns
getColumnIndexback to summary
public int getColumnIndex(Object identifier)

Implements javax.swing.table.TableColumnModel.getColumnIndex.

Returns the index of the first column in the tableColumns array whose identifier is equal to identifier, when compared using equals.

Parameters
identifier:Object

the identifier object

Returns:int

the index of the first column in the tableColumns array whose identifier is equal to identifier

Exceptions
IllegalArgumentException:
if identifier is null, or if no TableColumn has this identifier
See Also
getColumn
getColumnIndexAtXback to summary
public int getColumnIndexAtX(int x)

Implements javax.swing.table.TableColumnModel.getColumnIndexAtX.

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.

Parameters
x:int

the horizontal location of interest

Returns:int

the index of the column or -1 if no column is found

See Also
javax.swing.JTable#columnAtPoint
getColumnMarginback to summary
public int getColumnMargin()

Implements javax.swing.table.TableColumnModel.getColumnMargin.

Returns the width margin for TableColumn. The default columnMargin is 1.

Returns:int

the maximum width for the TableColumn

See Also
setColumnMargin
getColumnModelListenersback to summary
public TableColumnModelListener[] getColumnModelListeners()

Returns an array of all the column model listeners registered on this model.

Returns:TableColumnModelListener[]

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, removeColumnModelListener
getColumnsback to summary
public Enumeration<TableColumn> getColumns()

Implements javax.swing.table.TableColumnModel.getColumns.

Returns an Enumeration of all the columns in the model.

Returns:Enumeration<TableColumn>

an Enumeration of the columns in the model

getColumnSelectionAllowedback to summary
public boolean getColumnSelectionAllowed()

Implements javax.swing.table.TableColumnModel.getColumnSelectionAllowed.

Returns true if column selection is allowed, otherwise false. The default is false.

Returns:boolean

the columnSelectionAllowed property

getListenersback to summary
public <T extends EventListener> T[] getListeners(Class<T> listenerType)

Returns an array of all the objects currently registered as 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.
Parameters
<T>
the listener type
listenerType:Class<T>

the type of listeners requested

Returns:T[]

an array of all objects registered as FooListeners on this model, or an empty array if no such listeners have been added

Exceptions
ClassCastException:
if listenerType doesn't specify a class or interface that implements java.util.EventListener
Since
1.3
See Also
getColumnModelListeners
getSelectedColumnCountback to summary
public int getSelectedColumnCount()

Implements javax.swing.table.TableColumnModel.getSelectedColumnCount.

Returns the number of columns selected.

Returns:int

the number of columns selected

getSelectedColumnsback to summary
public int[] getSelectedColumns()

Implements javax.swing.table.TableColumnModel.getSelectedColumns.

Returns an array of selected columns. If selectionModel is null, returns an empty array.

Returns:int[]

an array of selected columns or an empty array if nothing is selected or the selectionModel is null

getSelectionModelback to summary
public ListSelectionModel getSelectionModel()

Implements javax.swing.table.TableColumnModel.getSelectionModel.

Returns the ListSelectionModel that is used to maintain column selection state.

Returns:ListSelectionModel

the object that provides column selection state. Or null if row selection is not allowed.

See Also
setSelectionModel
getTotalColumnWidthback to summary
public int getTotalColumnWidth()

Implements javax.swing.table.TableColumnModel.getTotalColumnWidth.

Returns the total combined width of all columns.

Returns:int

the totalColumnWidth property

invalidateWidthCacheback to summary
private void invalidateWidthCache()
moveColumnback to summary
public void moveColumn(int columnIndex, int newIndex)

Implements javax.swing.table.TableColumnModel.moveColumn.

Moves the column and heading at 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.

Parameters
columnIndex:int

the index of column to be moved

newIndex:int

new index to move the column

Exceptions
IllegalArgumentException:
if column or newIndex are not in the valid range
propertyChangeback to summary
public void propertyChange(PropertyChangeEvent evt)

Implements java.beans.PropertyChangeListener.propertyChange.

Property Change Listener change method. Used to track changes to the column width or preferred column width.

Parameters
evt:PropertyChangeEvent

PropertyChangeEvent

recalcWidthCacheback to summary
protected void recalcWidthCache()

Recalculates the total combined width of all columns. Updates the totalColumnWidth property.

removeColumnback to summary
public void removeColumn(TableColumn column)

Implements javax.swing.table.TableColumnModel.removeColumn.

Deletes the 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.

Parameters
column:TableColumn

the TableColumn to be removed

See Also
addColumn
removeColumnModelListenerback to summary
public void removeColumnModelListener(TableColumnModelListener x)

Implements javax.swing.table.TableColumnModel.removeColumnModelListener.

Removes a listener for table column model events.

Parameters
x:TableColumnModelListener

a TableColumnModelListener object

setColumnMarginback to summary
public void setColumnMargin(int newMargin)

Implements javax.swing.table.TableColumnModel.setColumnMargin.

Sets the column margin to newMargin. This method also posts a columnMarginChanged event to its listeners.

Parameters
newMargin:int

the new margin width, in pixels

See Also
getColumnMargin, getTotalColumnWidth
setColumnSelectionAllowedback to summary
public void setColumnSelectionAllowed(boolean flag)

Implements javax.swing.table.TableColumnModel.setColumnSelectionAllowed.

Sets whether column selection is allowed. The default is false.

Parameters
flag:boolean

true if column selection will be allowed, false otherwise

setSelectionModelback to summary
public void setSelectionModel(ListSelectionModel newModel)

Implements javax.swing.table.TableColumnModel.setSelectionModel.

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.

Parameters
newModel:ListSelectionModel

the new selection model

Exceptions
IllegalArgumentException:
if newModel is null
See Also
getSelectionModel
valueChangedback to summary
public void valueChanged(ListSelectionEvent e)

Implements javax.swing.event.ListSelectionListener.valueChanged.

A ListSelectionListener that forwards ListSelectionEvents when there is a column selection change.

Parameters
e:ListSelectionEvent

the change event