javax.swing.table

Class TableColumn

public class TableColumn extends Object implements Serializable

Represents the attributes of a column in a table, including the column index, width, minimum width, preferred width and maximum width.
Field Summary
protected TableCellEditorcellEditor
An editor for the regular cells in this column.
protected TableCellRenderercellRenderer
The renderer for the regular cells in this column.
static StringCELL_RENDERER_PROPERTY
The name for the cellRenderer property.
static StringCOLUMN_WIDTH_PROPERTY
The name for the columnWidth property (this field is obsolete and no longer used).
protected TableCellRendererheaderRenderer
The renderer for the column header.
protected ObjectheaderValue
The value for the column header.
static StringHEADER_RENDERER_PROPERTY
The name for the headerRenderer property.
static StringHEADER_VALUE_PROPERTY
The name for the headerValue property.
protected Objectidentifier
The identifier for the column.
protected booleanisResizable
A flag that determines whether or not the column is resizable (the default is true).
protected intmaxWidth
The maximum width for the column.
protected intminWidth
The minimum width for the column.
protected intmodelIndex
The index of the corresponding column in the table model.
protected intresizedPostingDisableCount
resizedPostingDisableCount
protected intwidth
The current width for the column.
Constructor Summary
TableColumn()
Creates a new TableColumn that maps to column 0 in the related table model.
TableColumn(int modelIndex)
Creates a new TableColumn that maps to the specified column in the related table model.
TableColumn(int modelIndex, int width)
Creates a new TableColumn that maps to the specified column in the related table model, and has the specified width.
TableColumn(int modelIndex, int width, TableCellRenderer cellRenderer, TableCellEditor cellEditor)
Creates a new TableColumn that maps to the specified column in the related table model, and has the specified width, cellRenderer and cellEditor.
Method Summary
voidaddPropertyChangeListener(PropertyChangeListener listener)
Adds a listener so that it receives {@link PropertyChangeEvent} notifications from this column.
protected TableCellRenderercreateDefaultHeaderRenderer()
Creates and returns a default renderer for the column header (in this case, a new instance of {@link DefaultTableCellRenderer}).
voiddisableResizedPosting()
This method is empty, unused and deprecated.
voidenableResizedPosting()
This method is empty, unused and deprecated.
TableCellEditorgetCellEditor()
Returns the cell editor for the column (the default value is null).
TableCellRenderergetCellRenderer()
Returns the renderer for the table cells in this column.
TableCellRenderergetHeaderRenderer()
Returns the renderer for the column header.
ObjectgetHeaderValue()
Returns the header value.
ObjectgetIdentifier()
Returns the identifier for the column, or {@link #getHeaderValue()} if the identifier is null.
intgetMaxWidth()
Returns the maximum width for the column (the default value is {@link Integer#MAX_VALUE}).
intgetMinWidth()
Returns the TableColumn's minimum width (the default value is 15).
intgetModelIndex()
Returns the index of the column in the related {@link TableModel} that this TableColumn maps to.
intgetPreferredWidth()
Returns the preferred width for the column (the default value is 75).
PropertyChangeListener[]getPropertyChangeListeners()
Returns the property change listeners for this TableColumn.
booleangetResizable()
Returns the flag that controls whether or not the column is resizable.
intgetWidth()
Returns the width for the column (the default value is 75).
voidremovePropertyChangeListener(PropertyChangeListener listener)
Removes a listener so that it no longer receives {@link PropertyChangeEvent} notifications from this column.
voidsetCellEditor(TableCellEditor cellEditor)
Sets the cell editor for the column and sends a {@link PropertyChangeEvent} (with the property name 'cellEditor') to all registered listeners.
voidsetCellRenderer(TableCellRenderer renderer)
Sets the renderer for cells in this column and sends a {@link PropertyChangeEvent} (with the property name {@link #CELL_RENDERER_PROPERTY}) to all registered listeners.
voidsetHeaderRenderer(TableCellRenderer renderer)
Sets the renderer for the column header and sends a {@link PropertyChangeEvent} (with the property name {@link #HEADER_RENDERER_PROPERTY}) to all registered listeners.
voidsetHeaderValue(Object headerValue)
Sets the header value and sends a {@link PropertyChangeEvent} (with the property name {@link #HEADER_VALUE_PROPERTY}) to all registered listeners.
voidsetIdentifier(Object identifier)
Sets the identifier for the column and sends a {@link PropertyChangeEvent} (with the property name 'identifier') to all registered listeners.
voidsetMaxWidth(int maxWidth)
Sets the maximum width for the column and sends a {@link PropertyChangeEvent} (with the property name 'maxWidth') to all registered listeners.
voidsetMinWidth(int minWidth)
Sets the minimum width for the column and sends a {@link PropertyChangeEvent} (with the property name 'minWidth') to all registered listeners.
voidsetModelIndex(int modelIndex)
Sets the index of the column in the related {@link TableModel} that this TableColumn maps to, and sends a {@link PropertyChangeEvent} (with the property name 'modelIndex') to all registered listeners.
voidsetPreferredWidth(int preferredWidth)
Sets the preferred width for the column and sends a {@link PropertyChangeEvent} (with the property name 'preferredWidth') to all registered listeners.
voidsetResizable(boolean isResizable)
Sets the flag that controls whether or not the column is resizable, and sends a {@link PropertyChangeEvent} (with the property name 'isResizable') to all registered listeners.
voidsetWidth(int newWidth)
Sets the width for the column and sends a {@link PropertyChangeEvent} (with the property name 'width') to all registered listeners.
voidsizeWidthToFit()
Sets the minimum, maximum, preferred and current width to match the minimum, maximum and preferred width of the header renderer component.

Field Detail

cellEditor

protected TableCellEditor cellEditor
An editor for the regular cells in this column.

cellRenderer

protected TableCellRenderer cellRenderer
The renderer for the regular cells in this column.

CELL_RENDERER_PROPERTY

public static final String CELL_RENDERER_PROPERTY
The name for the cellRenderer property.

COLUMN_WIDTH_PROPERTY

public static final String COLUMN_WIDTH_PROPERTY
The name for the columnWidth property (this field is obsolete and no longer used). Note also that the typo in the value string is deliberate, to match the specification.

headerRenderer

protected TableCellRenderer headerRenderer
The renderer for the column header.

headerValue

protected Object headerValue
The value for the column header.

HEADER_RENDERER_PROPERTY

public static final String HEADER_RENDERER_PROPERTY
The name for the headerRenderer property.

HEADER_VALUE_PROPERTY

public static final String HEADER_VALUE_PROPERTY
The name for the headerValue property.

identifier

protected Object identifier
The identifier for the column.

isResizable

protected boolean isResizable
A flag that determines whether or not the column is resizable (the default is true).

maxWidth

protected int maxWidth
The maximum width for the column.

minWidth

protected int minWidth
The minimum width for the column.

modelIndex

protected int modelIndex
The index of the corresponding column in the table model.

resizedPostingDisableCount

protected transient int resizedPostingDisableCount

Deprecated: 1.3

resizedPostingDisableCount

width

protected int width
The current width for the column.

Constructor Detail

TableColumn

public TableColumn()
Creates a new TableColumn that maps to column 0 in the related table model. The default width is 75 units.

TableColumn

public TableColumn(int modelIndex)
Creates a new TableColumn that maps to the specified column in the related table model. The default width is 75 units.

Parameters: modelIndex the index of the column in the model

TableColumn

public TableColumn(int modelIndex, int width)
Creates a new TableColumn that maps to the specified column in the related table model, and has the specified width.

Parameters: modelIndex the index of the column in the model width the width

TableColumn

public TableColumn(int modelIndex, int width, TableCellRenderer cellRenderer, TableCellEditor cellEditor)
Creates a new TableColumn that maps to the specified column in the related table model, and has the specified width, cellRenderer and cellEditor.

Parameters: modelIndex the index of the column in the model width the width cellRenderer the cell renderer (null permitted). cellEditor the cell editor (null permitted).

Method Detail

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Adds a listener so that it receives {@link PropertyChangeEvent} notifications from this column. The properties defined by the column are:

Parameters: listener the listener to add (null is ignored).

See Also: removePropertyChangeListener

createDefaultHeaderRenderer

protected TableCellRenderer createDefaultHeaderRenderer()
Creates and returns a default renderer for the column header (in this case, a new instance of {@link DefaultTableCellRenderer}).

Returns: A default renderer for the column header.

disableResizedPosting

public void disableResizedPosting()

Deprecated: 1.3

This method is empty, unused and deprecated.

enableResizedPosting

public void enableResizedPosting()

Deprecated: 1.3

This method is empty, unused and deprecated.

getCellEditor

public TableCellEditor getCellEditor()
Returns the cell editor for the column (the default value is null).

Returns: The cell editor (possibly null).

See Also: setCellEditor

getCellRenderer

public TableCellRenderer getCellRenderer()
Returns the renderer for the table cells in this column.

Returns: The cell renderer (possibly null).

See Also: setCellRenderer

getHeaderRenderer

public TableCellRenderer getHeaderRenderer()
Returns the renderer for the column header.

Returns: The renderer for the column header (possibly null).

See Also: setHeaderRenderer

getHeaderValue

public Object getHeaderValue()
Returns the header value.

Returns: the value of the header.

See Also: getHeaderValue

getIdentifier

public Object getIdentifier()
Returns the identifier for the column, or {@link #getHeaderValue()} if the identifier is null.

Returns: The identifier (or {@link #getHeaderValue()} if the identifier is null).

getMaxWidth

public int getMaxWidth()
Returns the maximum width for the column (the default value is {@link Integer#MAX_VALUE}).

Returns: The maximum width for the column.

See Also: TableColumn

getMinWidth

public int getMinWidth()
Returns the TableColumn's minimum width (the default value is 15).

Returns: The minimum width.

See Also: TableColumn

getModelIndex

public int getModelIndex()
Returns the index of the column in the related {@link TableModel} that this TableColumn maps to.

Returns: the model index.

See Also: TableColumn

getPreferredWidth

public int getPreferredWidth()
Returns the preferred width for the column (the default value is 75).

Returns: The preferred width.

See Also: TableColumn

getPropertyChangeListeners

public PropertyChangeListener[] getPropertyChangeListeners()
Returns the property change listeners for this TableColumn. An empty array is returned if there are currently no listeners registered.

Returns: The property change listeners registered with this column.

Since: 1.4

getResizable

public boolean getResizable()
Returns the flag that controls whether or not the column is resizable.

Returns: true if this column is resizable, false otherwise.

See Also: TableColumn

getWidth

public int getWidth()
Returns the width for the column (the default value is 75).

Returns: The width.

See Also: TableColumn

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Removes a listener so that it no longer receives {@link PropertyChangeEvent} notifications from this column. If listener is not registered with the column, or is null, this method does nothing.

Parameters: listener the listener to remove (null is ignored).

setCellEditor

public void setCellEditor(TableCellEditor cellEditor)
Sets the cell editor for the column and sends a {@link PropertyChangeEvent} (with the property name 'cellEditor') to all registered listeners.

Parameters: cellEditor the cell editor (null permitted).

See Also: getCellEditor

setCellRenderer

public void setCellRenderer(TableCellRenderer renderer)
Sets the renderer for cells in this column and sends a {@link PropertyChangeEvent} (with the property name {@link #CELL_RENDERER_PROPERTY}) to all registered listeners.

Parameters: renderer the cell renderer (null permitted).

See Also: getCellRenderer

setHeaderRenderer

public void setHeaderRenderer(TableCellRenderer renderer)
Sets the renderer for the column header and sends a {@link PropertyChangeEvent} (with the property name {@link #HEADER_RENDERER_PROPERTY}) to all registered listeners.

Parameters: renderer the header renderer (null permitted).

See Also: getHeaderRenderer

setHeaderValue

public void setHeaderValue(Object headerValue)
Sets the header value and sends a {@link PropertyChangeEvent} (with the property name {@link #HEADER_VALUE_PROPERTY}) to all registered listeners.

Parameters: headerValue the value of the header (null permitted).

See Also: getHeaderValue

setIdentifier

public void setIdentifier(Object identifier)
Sets the identifier for the column and sends a {@link PropertyChangeEvent} (with the property name 'identifier') to all registered listeners.

Parameters: identifier the identifier (null permitted).

See Also: getIdentifier

setMaxWidth

public void setMaxWidth(int maxWidth)
Sets the maximum width for the column and sends a {@link PropertyChangeEvent} (with the property name 'maxWidth') to all registered listeners. If the current width and/or preferredWidth are greater than the new maximum width, they are adjusted accordingly.

Parameters: maxWidth the maximum width.

See Also: getMaxWidth

setMinWidth

public void setMinWidth(int minWidth)
Sets the minimum width for the column and sends a {@link PropertyChangeEvent} (with the property name 'minWidth') to all registered listeners. If the current width and/or preferredWidth are less than the new minimum width, they are adjusted accordingly.

Parameters: minWidth the minimum width (negative values are treated as 0).

See Also: getMinWidth

setModelIndex

public void setModelIndex(int modelIndex)
Sets the index of the column in the related {@link TableModel} that this TableColumn maps to, and sends a {@link PropertyChangeEvent} (with the property name 'modelIndex') to all registered listeners.

Parameters: modelIndex the column index in the model.

See Also: getModelIndex

setPreferredWidth

public void setPreferredWidth(int preferredWidth)
Sets the preferred width for the column and sends a {@link PropertyChangeEvent} (with the property name 'preferredWidth') to all registered listeners. If necessary, the supplied value will be adjusted to fit in the range {@link #getMinWidth()} to {@link #getMaxWidth()}.

Parameters: preferredWidth the preferred width.

See Also: getPreferredWidth

setResizable

public void setResizable(boolean isResizable)
Sets the flag that controls whether or not the column is resizable, and sends a {@link PropertyChangeEvent} (with the property name 'isResizable') to all registered listeners.

Parameters: isResizable true if this column is resizable, false otherwise.

See Also: getResizable

setWidth

public void setWidth(int newWidth)
Sets the width for the column and sends a {@link PropertyChangeEvent} (with the property name 'width') to all registered listeners. If the new width falls outside the range getMinWidth() to getMaxWidth() it is adjusted to the appropriate boundary value.

Parameters: newWidth the width.

See Also: getWidth

sizeWidthToFit

public void sizeWidthToFit()
Sets the minimum, maximum, preferred and current width to match the minimum, maximum and preferred width of the header renderer component. If there is no header renderer component, this method does nothing.