|
JavaTM 2 Platform Std. Ed. v1.3.1 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--javax.swing.table.TableColumn
A TableColumn
represents all the attributes of a column in a
JTable
, such as width, resizibility, 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 the
setDefaultRenderer
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 the
JTable
and the columns in the TableModel
.
The modelIndex
is the column in the
TableModel
, which will be queried for the data values for the
cells in this column. As the column moves around in the view this
modelIndex
does not change.
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. A future release of Swing will provide support for long term persistence.
TableColumnModel
,
DefaultTableColumnModel
,
JTableHeader.getDefaultRenderer()
,
JTable.getDefaultRenderer(Class)
,
JTable.getDefaultEditor(Class)
,
JTable.getCellRenderer(int, int)
,
JTable.getCellEditor(int, int)
, Serialized FormField Summary | |
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 the
TableColumn as 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. as of Java 2 platform v1.3 |
protected int |
width
The width of the column. |
Constructor Summary | |
TableColumn()
Cover method, using a default model index of 0, default width of 75, a null renderer and a
null 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 a
null editor. |
|
TableColumn(int modelIndex,
int width,
TableCellRenderer cellRenderer,
TableCellEditor cellEditor)
Creates and initializes an instance of TableColumn with modelIndex . |
Method Summary | |
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. as of Java 2 platform v1.3 |
void |
enableResizedPosting()
Deprecated. as of Java 2 platform v1.3 |
TableCellEditor |
getCellEditor()
Returns the TableCellEditor used by the
JTable to edit values for this column. |
TableCellRenderer |
getCellRenderer()
Returns the TableCellRenderer used by the
JTable to draw
values for this column. |
TableCellRenderer |
getHeaderRenderer()
Returns the TableCellRenderer used to draw the header of the
TableColumn . |
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 . |
boolean |
getResizable()
Returns true if the user is allowed to resize the TableColumn '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 the
TableColumn '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 to
anIdentifier . |
void |
setMaxWidth(int maxWidth)
Sets the TableColumn 's maximum width to
maxWidth ; also adjusts the width and preferred
width if they are greater than this value. |
void |
setMinWidth(int minWidth)
Sets the TableColumn 's minimum width to
minWidth ; also adjusts the current width
and preferred width if they are less than this value. |
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 the JTable , use setPreferredWidth instead. |
void |
sizeWidthToFit()
Resizes the TableColumn to fit the width of its header cell. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final String COLUMN_WIDTH_PROPERTY
public static final String HEADER_VALUE_PROPERTY
public static final String HEADER_RENDERER_PROPERTY
public static final String CELL_RENDERER_PROPERTY
protected int modelIndex
TableColumn
. As columns are moved around in the
view modelIndex
remains constant.protected Object identifier
JTable
; identifiers may be set in the
TableColumn
as as an
optional way to tag and locate table columns. The table package does
not modify or invoke any methods in these identifer objects other
than the equals
method which is used in the
getColumnIndex()
method in the
DefaultTableColumnModel
.protected int width
protected int minWidth
protected int maxWidth
protected TableCellRenderer headerRenderer
protected Object headerValue
protected TableCellRenderer cellRenderer
protected TableCellEditor cellEditor
protected boolean isResizable
protected transient int resizedPostingDisableCount
Constructor Detail |
public TableColumn()
null
renderer and a
null
editor.
This method is intended for serialization.TableColumn(int, int, TableCellRenderer, TableCellEditor)
public TableColumn(int modelIndex)
null
renderer and a null
editor.TableColumn(int, int, TableCellRenderer, TableCellEditor)
public TableColumn(int modelIndex, int width)
null
renderer and a
null
editor.TableColumn(int, int, TableCellRenderer, TableCellEditor)
public TableColumn(int modelIndex, int width, TableCellRenderer cellRenderer, TableCellEditor cellEditor)
TableColumn
with modelIndex
.
All TableColumn
constructors delegate to this one.
The modelIndex
is the index of the column
in the model which will supply the data for this column in the table.
The modelIndex
does not change as the columns are reordered
in the view. The width parameter is used to set both the
preferredWidth
for this
column and the initial width. The renderer and editor are the objects
used respectively to render and edit values in this column. When
these are null
, default values, provided by the
getDefaultRenderer
and getDefaultEditor
methods in the
JTable
class are used to
provide defaults based on the type of the data in this column.
This column-centric rendering strategy can be circumvented by overriding
the getCellRenderer
methods in the JTable
.
JTable.getDefaultRenderer(Class)
,
JTable.getDefaultEditor(Class)
,
JTable.getCellRenderer(int, int)
,
JTable.getCellEditor(int, int)
Method Detail |
public void setModelIndex(int modelIndex)
TableColumn
. As the TableColumn
is moved around in the view the model index remains constant.modelIndex
- the new modelIndexpublic int getModelIndex()
modelIndex
propertypublic void setIdentifier(Object identifier)
TableColumn
's identifier to
anIdentifier
.
Note: identifiers are not used by the JTable
,
they are purely a
convenience for the external tagging and location of columns.
identifier
- an identifier for this columngetIdentifier()
public Object getIdentifier()
identifier
object for this column.
Note identifiers are not used by JTable
,
they are purely a convenience for external use.
If the identifier
is null
,
getIdentifier()
returns getHeaderValue
as a default.identifier
propertysetIdentifier(java.lang.Object)
public void setHeaderValue(Object headerValue)
Object
whose string representation will be
used as the value for the headerRenderer
. When the
TableColumn
is created, the default headerValue
is null
.headerValue
- the new headerValuegetHeaderValue()
public Object getHeaderValue()
Object
used as the value for the header
renderer.headerValue
propertysetHeaderValue(java.lang.Object)
public void setHeaderRenderer(TableCellRenderer headerRenderer)
TableCellRenderer
used to draw the
TableColumn
's header to headerRenderer
.headerRenderer
- the new headerRenderergetHeaderRenderer()
public TableCellRenderer getHeaderRenderer()
TableCellRenderer
used to draw the header of the
TableColumn
. When the headerRenderer
is
null
, the JTableHeader
uses its defaultRenderer
. The default value for a
headerRenderer
is null
.headerRenderer
propertysetHeaderRenderer(javax.swing.table.TableCellRenderer)
,
setHeaderValue(java.lang.Object)
,
JTableHeader.getDefaultRenderer()
public void setCellRenderer(TableCellRenderer cellRenderer)
TableCellRenderer
used by JTable
to draw individual values for this column.cellRenderer
- the new cellRenderergetCellRenderer()
public TableCellRenderer getCellRenderer()
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
.
When the cellRenderer
is null
,
the JTable
uses a default renderer based on the
class of the cells in that column. The default value for a
cellRenderer
is null
.cellRenderer
propertysetCellRenderer(javax.swing.table.TableCellRenderer)
,
JTable.setDefaultRenderer(java.lang.Class, javax.swing.table.TableCellRenderer)
public void setCellEditor(TableCellEditor cellEditor)
cellEditor
- the new cellEditorgetCellEditor()
public TableCellEditor getCellEditor()
TableCellEditor
used by the
JTable
to edit values for this column. When the
cellEditor
is null
, the JTable
uses a default editor based on the
class of the cells in that column. The default value for a
cellEditor
is null
.cellEditor
propertysetCellEditor(javax.swing.table.TableCellEditor)
,
JTable.setDefaultEditor(java.lang.Class, javax.swing.table.TableCellEditor)
public void setWidth(int width)
JTable
, use setPreferredWidth
instead.
Like a layout manager in the
AWT, the JTable
adjusts a column's width automatically
whenever the
table itself changes size, or a column's preferred width is changed.
Setting widths programmatically therefore has no long term effect.
This method sets this column's width to width
.
If width
exceeds the minimum or maximum width,
it is adjusted to the appropriate limiting value.
width
- the new widthgetWidth()
,
setMinWidth(int)
,
setMaxWidth(int)
,
setPreferredWidth(int)
,
JTable.sizeColumnsToFit(int)
public int getWidth()
TableColumn
. The default width is
75.width
propertysetWidth(int)
public void setPreferredWidth(int preferredWidth)
preferredWidth
.
If preferredWidth
exceeds the minimum or maximum width,
it is adjusted to the appropriate limiting value.
For details on how the widths of columns in the JTable
(and JTableHeader
) are calculated from the
preferredWidth
,
see the sizeColumnsToFit
method in JTable
.
preferredWidth
- the new preferred widthgetPreferredWidth()
,
JTable.sizeColumnsToFit(int)
public int getPreferredWidth()
TableColumn
.
The default preferred width is 75.preferredWidth
propertysetPreferredWidth(int)
public void setMinWidth(int minWidth)
TableColumn
's minimum width to
minWidth
; also adjusts the current width
and preferred width if they are less than this value.minWidth
- the new minimum widthgetMinWidth()
,
setPreferredWidth(int)
,
setMaxWidth(int)
public int getMinWidth()
TableColumn
. The
TableColumn
's width can't be made less than this either
by the user or programmatically. The default minWidth is 15.minWidth
propertysetMinWidth(int)
public void setMaxWidth(int maxWidth)
TableColumn
's maximum width to
maxWidth
; also adjusts the width and preferred
width if they are greater than this value.maxWidth
- the new maximum widthgetMaxWidth()
,
setPreferredWidth(int)
,
setMinWidth(int)
public int getMaxWidth()
TableColumn
. The
TableColumn
's width can't be made larger than this
either by the user or programmatically. The default maxWidth
is Integer.MAX_VALUE.maxWidth
propertysetMaxWidth(int)
public void setResizable(boolean isResizable)
isResizable
- if true, resizing is allowed; otherwise falsegetResizable()
public boolean getResizable()
TableColumn
's
width, false otherwise. You can change the width programmatically
regardless of this setting. The default is true.isResizable
propertysetResizable(boolean)
public void sizeWidthToFit()
TableColumn
to fit the width of its header cell.
This method does nothing if the header renderer is null
(the default case).setPreferredWidth(int)
public void disableResizedPosting()
public void enableResizedPosting()
public void addPropertyChangeListener(PropertyChangeListener listener)
PropertyChangeListener
to the listener list.
The listener is registered for all properties.
A PropertyChangeEvent
will get fired in response to an
explicit call to 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.
listener
- the listener to be addedpublic void removePropertyChangeListener(PropertyChangeListener listener)
PropertyChangeListener
from the listener list.
The PropertyChangeListener
to be removed was registered
for all properties.listener
- the listener to be removedprotected TableCellRenderer createDefaultHeaderRenderer()
TableColumn
constructor. Previously this method was used by the
TableColumn
to create a default header renderer.
As of Java 2 platform v1.3, the default header renderer is null
.
JTableHeader
now provides its own shared default
renderer, just as the JTable
does for its cell renderers.JTableHeader.createDefaultRenderer()
|
JavaTM 2 Platform Std. Ed. v1.3.1 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Java, Java 2D, and JDBC are trademarks or registered trademarks of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-2001 Sun Microsystems, Inc. 901 San Antonio Road
Palo Alto, California, 94303, U.S.A. All Rights Reserved.