All Packages Class Hierarchy This Package Previous Next Index
Class java.awt.swing.table.TableColumn
java.lang.Object
|
+----java.awt.swing.table.TableColumn
- public class TableColumn
- extends Object
- implements Serializable
An TableColumn represents all the attributes of a column in an
JTable, such as width, resizibility, minimum and maximum width.
In addition, TableColumn also helps to determine how the JTable
interpret and display the value objects from the TableModel in
the column. This is done using the cellRenderer of the column. For
example, the TableModel can give the table Boolean objects
for a column. If the column's cellRenderer is an JCellRenderer
initialized with a JCheckBox component then the table will be able
to show the Boolean value as a checkbox. Similarly if the column's
cellEditor is set correctly the user will then be able to modify the cell
value. This pairing of source's value object with the corresponding
cellRender and cellEditor to display and edit the value gives the table
a great deal of power and flexibility. Because the table does not
need to know anything about the data being displayed, the user is free to
customize it in anyway imaginable. If the user want to display images
for a column, then set the cellRenderer to an image renderer which
can display an image. etc.
The user allocates a column by passing in an identifier object. This
identifer can be any Object but it should be unique for each column in a
given table. This is a simpler and more flexible identification mechaism
than using an integer index because the user can reorder columns in
a table. The unique identifier object frees the TableModel from
needing to keep track of all column reorderings to know what column is at
what index. For example, A table has 3 columns: First Name, Last
Name, and age. When the table need the value object for a given column
and row, it will ask the TableModel, getValueAt() and it
will pass the TableColumn's identifier object and the row index
as arguments. The data model can simply compare the identifer to find
out the table needs data for which of the 3 columns.
- See Also:
- TableColumnModel, DefaultTableColumnModel
CELL_RENDERER_PROPERTY- Bound property name.
cellEditor- The editor used to edit the data cells of the column
cellRenderer- The renderer used to draw the data cells of the column
COLUMN_WIDTH_PROPERTY- Bound property name.
HEADER_RENDERER_PROPERTY- Bound property name.
HEADER_VALUE_PROPERTY- Bound property name.
headerRenderer- The renderer used to draw the header of the column
headerValue- The header value of the column
identifier- This object is set by the source to act as an identifier of
this column, so the source can tell the columns apart.
isResizable- Resizable flag
maxWidth- The maximum width of the column
minWidth- The minimum width of the column
resizedPostingDisableCount- Counter used to disable posting of resizing notifications until the
end of the resize
width- The width of the column
TableColumn()
- Creates an empty TableColumn with the String "Column"
as the identifier.
TableColumn(Object)
- Creates and initializes an instance of TableColumn with
anIdentifier.
addPropertyChangeListener(PropertyChangeListener)
- Add a PropertyChangeListener to the listener list.
createDefaultCellEditor()
-
createDefaultCellRenderer()
-
createDefaultHeaderRenderer()
-
disableResizedPosting()
-
enableResizedPosting()
-
getCellEditor()
- Returns the TableCellEditor used by the JTable to draw
values for this column.
getCellRenderer()
- Returns the TableCellRenderer used by the JTable to draw
values for this column.
getHeaderRenderer()
- Returns the TableCellRenderer used to draw the header of the
TableColumn.
getHeaderValue()
- Returns the Object used as the value for the header renderer.
getIdentifier()
- Returns the identifier object for this column
getMaxWidth()
- Returns the maximum width for the TableColumn.
getMinWidth()
- Returns the minimum width for the TableColumn.
getResizable()
- Returns true if the user is allowed to resize the TableColumn
width, false otherwise.
getWidth()
- Returns the width of the TableColumn.
removePropertyChangeListener(PropertyChangeListener)
- Remove a PropertyChangeListener from the listener list.
setCellEditor(TableCellEditor)
- Sets the TableCellEditor used by JTable to draw individual
values for this column to anEditor.
setCellRenderer(TableCellRenderer)
- Sets the TableCellRenderer used by JTable to draw
individual values for this column to aRenderer.
setHeaderRenderer(TableCellRenderer)
- Sets the TableCellRenderer used to draw the TableColumn's
header to aRenderer.
setHeaderValue(Object)
- Sets the Object used as the value for the headerRenderer
Posts a bound property change notification with the name
HEADER_VALUE_PROPERTY.
setIdentifier(Object)
- Sets the TableColumn's identifier to anIdentifier.
setMaxWidth(int)
- Sets the TableColumn's maximum width to newMaxWidth,
also adjusting the current width if it's greater than this value.
setMinWidth(int)
- Sets the TableColumn's minimum width to newMinWidth,
also adjusting the current width if it's less than this value.
setResizable(boolean)
- Sets whether the user can resize the receiver in its
JTableView.
setWidth(int)
- Sets this column's width to newWidth.
sizeWidthToFit()
- Resizes the TableColumn to fit the width of its header cell.
COLUMN_WIDTH_PROPERTY
public static final String COLUMN_WIDTH_PROPERTY
- Bound property name.
HEADER_VALUE_PROPERTY
public static final String HEADER_VALUE_PROPERTY
- Bound property name.
HEADER_RENDERER_PROPERTY
public static final String HEADER_RENDERER_PROPERTY
- Bound property name.
CELL_RENDERER_PROPERTY
public static final String CELL_RENDERER_PROPERTY
- Bound property name.
identifier
protected Object identifier
- This object is set by the source to act as an identifier of
this column, so the source can tell the columns apart.
The table view will not modify or invoke any methods in
this identifer object
width
protected int width
- The width of the column
minWidth
protected int minWidth
- The minimum width of the column
maxWidth
protected int maxWidth
- The maximum width of the column
headerRenderer
protected TableCellRenderer headerRenderer
- The renderer used to draw the header of the column
headerValue
protected Object headerValue
- The header value of the column
cellRenderer
protected TableCellRenderer cellRenderer
- The renderer used to draw the data cells of the column
cellEditor
protected TableCellEditor cellEditor
- The editor used to edit the data cells of the column
isResizable
protected boolean isResizable
- Resizable flag
resizedPostingDisableCount
protected transient int resizedPostingDisableCount
- Counter used to disable posting of resizing notifications until the
end of the resize
TableColumn
public TableColumn()
- Creates an empty TableColumn with the String "Column"
as the identifier. This is intended for the use
of the serialization code.
IMPORTANT: Users should not construct a TableColumn using
this constructor unless it is followed up by a proper
setIdentifier(). Otherwise, all columns will have
the same identifier and JTable will not behave
correctly.
TableColumn
public TableColumn(Object anIdentifier)
- Creates and initializes an instance of TableColumn with
anIdentifier. By default this also sets the headerValue
to null, which make it very easy to use a String that
is the column identifier as the name of the column.
- Parameters:
- anIdentifier - the identifier of this column
- Throws:
IllegalArgumentException
- if anIdentifier is null
- See Also:
- setHeaderValue
setIdentifier
public void setIdentifier(Object anIdentifier)
- Sets the TableColumn's identifier to anIdentifier.
This object is used by the TableModel to identify the data
corresponding to this column.
- Parameters:
- anIdentifier - the identifier of this column
- Throws:
IllegalArgumentException
- if anIdentifier is null
- See Also:
- getIdentifier
getIdentifier
public Object getIdentifier()
- Returns the identifier object for this column
- Returns:
- the idenitifer object for this column
- See Also:
- setIdentifier
setHeaderRenderer
public void setHeaderRenderer(TableCellRenderer aRenderer)
- Sets the TableCellRenderer used to draw the TableColumn's
header to aRenderer. Posts a bound property change notification
with the name HEADER_RENDERER_PROPERTY.
- Parameters:
- aRenderer - the new header renderer
- Throws:
IllegalArgumentException
- if aRenderer is null.
- See Also:
- getHeaderRenderer
getHeaderRenderer
public TableCellRenderer getHeaderRenderer()
- Returns the TableCellRenderer used to draw the header of the
TableColumn. The default header renderer is a
JCellRenderer initialized with a JLabel.
- Returns:
- the TableCellRenderer used to draw the header
- See Also:
- setHeaderRenderer, setHeaderValue
setHeaderValue
public void setHeaderValue(Object aValue)
- Sets the Object used as the value for the headerRenderer
Posts a bound property change notification with the name
HEADER_VALUE_PROPERTY. If header value is set to null,
the column's identifier will be used as the header value. This
allows for very simple creation of a TableColumn:
TableColumn newColumn = new TableColumn("Column Name");
There is no need to do a setHeaderValue() for the simple case of
using a String as both the unique identifier and the header value.
The default headerValue is null.
- Parameters:
- aValue - the new header value
- See Also:
- getHeaderValue
getHeaderValue
public Object getHeaderValue()
- Returns the Object used as the value for the header renderer.
If headerValue has not been set, then it returns the column's
identifier.
- Returns:
- the Object used as the value for the header renderer
- See Also:
- setHeaderValue
setCellRenderer
public void setCellRenderer(TableCellRenderer aRenderer)
- Sets the TableCellRenderer used by JTable to draw
individual values for this column to aRenderer. Posts a
bound property change notification with the name CELL_RENDERER_PROPERTY.
- Parameters:
- aRenderer - the new data cell renderer
- Throws:
IllegalArgumentException
- if aRenderer is null.
- See Also:
- getCellRenderer
getCellRenderer
public TableCellRenderer getCellRenderer()
- Returns the TableCellRenderer used by the JTable to draw
values for this column. The cellRenderer of the column not
only controls the visual look for the column, but is also used to
interpret the value object supplied by the TableModel. The
default cellRenderer is a JCellRenderer
initialized with a JLabel.
- Returns:
- the TableCellRenderer used by the JTable to
draw values for this column
- See Also:
- setCellRenderer
setCellEditor
public void setCellEditor(TableCellEditor anEditor)
- Sets the TableCellEditor used by JTable to draw individual
values for this column to anEditor. A null editor
means the column is not editable.
- Parameters:
- anEditor - the new data cell editor
- See Also:
- getCellEditor
getCellEditor
public TableCellEditor getCellEditor()
- Returns the TableCellEditor used by the JTable to draw
values for this column. The cellEditor of the column not
only controls the visual look for the column, but is also used to
interpret the value object supplied by the TableModel. The
default cellEditor is null.
- Returns:
- the TableCellEditor used by the JTable to
draw values for this column
- See Also:
- setCellEditor
setWidth
public void setWidth(int newWidth)
- Sets this column's width to newWidth. If newWidth
exceeds the minimum or maximum width, it's adjusted to the
appropriate limiting value. Posts a bound property
change notification with the name COLUMN_WIDTH_PROPERTY.
- Parameters:
- newWidth - The new width value
- See Also:
- getWidth, getMinWidth, setMinWidth, getMaxWidth, setMaxWidth
getWidth
public int getWidth()
- Returns the width of the TableColumn. The default width is
75.
- Returns:
- the width of the TableColumn
- See Also:
- setWidth, getMinWidth, setMinWidth, getMaxWidth, setMaxWidth
setMinWidth
public void setMinWidth(int newMinWidth)
- Sets the TableColumn's minimum width to newMinWidth,
also adjusting the current width if it's less than this value.
- Parameters:
- newMinWidth - the new minimum width value
- See Also:
- getWidth, setWidth, getMinWidth, getMaxWidth, setMaxWidth
getMinWidth
public int getMinWidth()
- Returns the minimum width for the TableColumn. The
TableColumn's width can't be made less than this either
by the user or programmatically. The default minWidth is 15.
- Returns:
- the minimum width for the TableColumn
- See Also:
- getWidth, setWidth, setMinWidth, getMaxWidth, setMaxWidth
setMaxWidth
public void setMaxWidth(int newMaxWidth)
- Sets the TableColumn's maximum width to newMaxWidth,
also adjusting the current width if it's greater than this value.
- Parameters:
- newMaxWidth - the new maximum width value
- See Also:
- getWidth, setWidth, getMinWidth, setMinWidth, getMaxWidth
getMaxWidth
public int getMaxWidth()
- Returns the maximum width for the TableColumn. The
TableColumn's width can't be made larger than this
either by the user or programmatically. The default maxWidth
is 2000.
- Returns:
- the maximum width for the TableColumn.
- See Also:
- getWidth, setWidth, getMinWidth, setMinWidth, setMaxWidth
setResizable
public void setResizable(boolean flag)
- Sets whether the user can resize the receiver in its
JTableView.
- Parameters:
- flag - true if the column isResizable
- See Also:
- getResizable
getResizable
public boolean getResizable()
- Returns true if the user is allowed to resize the TableColumn
width, false otherwise. You can change the width programmatically
regardless of this setting. The default is true.
- Returns:
- true if the user is allowed to resize the TableColumn
width, false otherwise.
- See Also:
- setResizable
sizeWidthToFit
public void sizeWidthToFit()
- Resizes the TableColumn to fit the width of its header cell.
If the maximum width is less than the width of the header, the
maximum is increased to the header's width. Similarly, if the
minimum width is greater than the width of the header, the minimum
is reduced to the header's width.
- See Also:
- setWidth, setMinWidth, setMaxWidth
disableResizedPosting
public void disableResizedPosting()
enableResizedPosting
public void enableResizedPosting()
addPropertyChangeListener
public void addPropertyChangeListener(PropertyChangeListener listener)
- Add a PropertyChangeListener to the listener list.
The listener is registered for all properties.
A PropertyChangeEvent will get fired in response to an
explicit setFont, setBackground, or SetForeground on the
current component. Note that if the current component is
inheriting its foreground, background, or font from its
container, then no event will be fired in response to a
change in the inherited property.
- Parameters:
- listener - The PropertyChangeListener to be added
removePropertyChangeListener
public void removePropertyChangeListener(PropertyChangeListener listener)
- Remove a PropertyChangeListener from the listener list.
This removes a PropertyChangeListener that was registered
for all properties.
- Parameters:
- listener - The PropertyChangeListener to be removed
createDefaultHeaderRenderer
protected TableCellRenderer createDefaultHeaderRenderer()
createDefaultCellRenderer
protected TableCellRenderer createDefaultCellRenderer()
createDefaultCellEditor
protected TableCellEditor createDefaultCellEditor()
All Packages Class Hierarchy This Package Previous Next Index
Submit a bug or feature