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

All Implemented Interfaces:

[Serializable](../../../../java.base/java/io/Serializable.html "interface in java.io")


public class TableColumn extends Object implements Serializable

A TableColumn represents all the attributes of a column in aJTable, such as width, resizability, minimum and maximum width. In addition, the TableColumn provides slots for a renderer and an editor that can be used to display and edit the values in this column.

It is also possible to specify renderers and editors on a per type basis rather than a per column basis - see thesetDefaultRenderer method in the JTable class. This default mechanism is only used when the renderer (or editor) in the TableColumn is null.

The TableColumn stores the link between the columns in theJTable and the columns in the TableModel. The modelIndex is the column in theTableModel, which will be queried for the data values for the cells in this column. As the column moves around in the view thismodelIndex does not change.

Note: Some implementations may assume that allTableColumnModels are unique, therefore we would recommend that the same TableColumn instance not be added more than once to a TableColumnModel. To show TableColumns with the same column of data from the model, create a new instance with the samemodelIndex.

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:

TableColumnModel, DefaultTableColumnModel, JTableHeader.getDefaultRenderer(), JTable.getDefaultRenderer(Class), JTable.getDefaultEditor(Class), JTable.getCellRenderer(int, int), JTable.getCellEditor(int, int)

Fields

Modifier and Type Field Description
static String CELL_RENDERER_PROPERTY Obsolete as of Java 2 platform v1.3.
protected TableCellEditor cellEditor The editor used to edit the data cells of the column.
protected TableCellRenderer cellRenderer The renderer used to draw the data cells of the column.
static String COLUMN_WIDTH_PROPERTY Obsolete as of Java 2 platform v1.3.
static String HEADER_RENDERER_PROPERTY Obsolete as of Java 2 platform v1.3.
static String HEADER_VALUE_PROPERTY Obsolete as of Java 2 platform v1.3.
protected TableCellRenderer headerRenderer The renderer used to draw the header of the column.
protected Object headerValue The header value of the column.
protected Object identifier This object is not used internally by the drawing machinery of the JTable; identifiers may be set in theTableColumn as an optional way to tag and locate table columns.
protected boolean isResizable If true, the user is allowed to resize the column; the default is true.
protected int maxWidth The maximum width of the column.
protected int minWidth The minimum width of the column.
protected int modelIndex The index of the column in the model which is to be displayed by this TableColumn.
protected int resizedPostingDisableCount Deprecated.
protected int width The width of the column.

Constructors

Constructor Description
TableColumn() Cover method, using a default model index of 0, default width of 75, a null renderer and anull editor.
TableColumn​(int modelIndex) Cover method, using a default width of 75, a null renderer and a null editor.
TableColumn​(int modelIndex, int width) Cover method, using a null renderer and anull editor.
TableColumn​(int modelIndex, int width,TableCellRenderer cellRenderer,TableCellEditor cellEditor) Creates and initializes an instance ofTableColumn with the specified model index, width, cell renderer, and cell editor; all TableColumn constructors delegate to this one.
Modifier and Type Method Description
void addPropertyChangeListener​(PropertyChangeListener listener) Adds a PropertyChangeListener to the listener list.
protected TableCellRenderer createDefaultHeaderRenderer() As of Java 2 platform v1.3, this method is not called by the TableColumn constructor.
void disableResizedPosting() Deprecated.
void enableResizedPosting() Deprecated.
TableCellEditor getCellEditor() Returns the TableCellEditor used by theJTable to edit values for this column.
TableCellRenderer getCellRenderer() Returns the TableCellRenderer used by theJTable to draw values for this column.
TableCellRenderer getHeaderRenderer() Returns the TableCellRenderer used to draw the header of theTableColumn.
Object getHeaderValue() Returns the Object used as the value for the header renderer.
Object getIdentifier() Returns the identifier object for this column.
int getMaxWidth() Returns the maximum width for the TableColumn.
int getMinWidth() Returns the minimum width for the TableColumn.
int getModelIndex() Returns the model index for this column.
int getPreferredWidth() Returns the preferred width of the TableColumn.
PropertyChangeListener[] getPropertyChangeListeners() Returns an array of all the PropertyChangeListeners added to this TableColumn with addPropertyChangeListener().
boolean getResizable() Returns true if the user is allowed to resize theTableColumn's width, false otherwise.
int getWidth() Returns the width of the TableColumn.
void removePropertyChangeListener​(PropertyChangeListener listener) Removes a PropertyChangeListener from the listener list.
void setCellEditor​(TableCellEditor cellEditor) Sets the editor to used by when a cell in this column is edited.
void setCellRenderer​(TableCellRenderer cellRenderer) Sets the TableCellRenderer used by JTable to draw individual values for this column.
void setHeaderRenderer​(TableCellRenderer headerRenderer) Sets the TableCellRenderer used to draw theTableColumn's header to headerRenderer.
void setHeaderValue​(Object headerValue) Sets the Object whose string representation will be used as the value for the headerRenderer.
void setIdentifier​(Object identifier) Sets the TableColumn's identifier toanIdentifier.
void setMaxWidth​(int maxWidth) Sets the TableColumn's maximum width tomaxWidth or, if maxWidth is less than the minimum width, to the minimum width.
void setMinWidth​(int minWidth) Sets the TableColumn's minimum width tominWidth, adjusting the new minimum width if necessary to ensure that 0 <= minWidth <= maxWidth.
void setModelIndex​(int modelIndex) Sets the model index for this column.
void setPreferredWidth​(int preferredWidth) Sets this column's preferred width to preferredWidth.
void setResizable​(boolean isResizable) Sets whether this column can be resized.
void setWidth​(int width) This method should not be used to set the widths of columns in theJTable, use setPreferredWidth instead.
void sizeWidthToFit() Resizes the TableColumn to fit the width of its header cell.

Methods declared in class java.lang.Object

[clone](../../../../java.base/java/lang/Object.html#clone%28%29), [equals](../../../../java.base/java/lang/Object.html#equals%28java.lang.Object%29), [finalize](../../../../java.base/java/lang/Object.html#finalize%28%29), [getClass](../../../../java.base/java/lang/Object.html#getClass%28%29), [hashCode](../../../../java.base/java/lang/Object.html#hashCode%28%29), [notify](../../../../java.base/java/lang/Object.html#notify%28%29), [notifyAll](../../../../java.base/java/lang/Object.html#notifyAll%28%29), [toString](../../../../java.base/java/lang/Object.html#toString%28%29), [wait](../../../../java.base/java/lang/Object.html#wait%28%29), [wait](../../../../java.base/java/lang/Object.html#wait%28long%29), [wait](../../../../java.base/java/lang/Object.html#wait%28long,int%29)