| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
JTable table = …;
DefaultTableColumnModel colModel = (DefaultTableColumnModel)table.getColumnModel();
Based on 14 examples
public class DefaultTableColumnModel extends Object implements TableColumnModel, PropertyChangeListener, ListSelectionListener, Serializable
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 JavaBeansTM
has been added to the java.beans
package.
Please see {@link java.beans.XMLEncoder}.
Field Summary | |
---|---|
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 |
tableColumns
Array of TableColumn objects in this model |
protected int |
totalColumnWidth
A local cache of the combined width of all columns |
Constructor Summary | |
---|---|
Creates a default table column model. |
Method Summary | |
---|---|
void |
addColumn(TableColumn aColumn) Appends aColumn to the end of the
tableColumns array.
|
void |
Adds a listener for table column model events. |
protected ListSelectionModel |
Creates a new default list selection model. |
protected void |
Notifies all listeners that have registered interest for notification on this event type. |
protected void |
Notifies all listeners that have registered interest for notification on this event type. |
protected void |
Notifies all listeners that have registered interest for notification on this event type. |
protected void |
Notifies all listeners that have registered interest for notification on this event type. |
protected void |
Notifies all listeners that have registered interest for notification on this event type. |
TableColumn |
getColumn(int columnIndex) Returns the TableColumn object for the column
at columnIndex .
|
int |
Returns the number of columns in the tableColumns array.
|
int |
getColumnIndex(Object identifier) Returns the index of the first column in the tableColumns
array whose identifier is equal to identifier ,
when compared using equals .
|
int |
getColumnIndexAtX(int x) Returns the index of the column that lies at position x ,
or -1 if no column covers this point.
|
int |
Returns the width margin for TableColumn .
|
TableColumnModelListener[] |
Returns an array of all the column model listeners registered on this model. |
Enumeration |
Returns an Enumeration of all the columns in the model.
|
boolean |
Returns true if column selection is allowed, otherwise false. |
EventListener[] |
getListeners(Class listenerType) Returns an array of all the objects currently registered as FooListener s
upon this model.
|
int |
Returns the number of columns selected. |
int[] |
Returns an array of selected columns. |
ListSelectionModel |
Returns the ListSelectionModel that is used to
maintain column selection state.
|
int |
Returns the total combined width of all columns. |
void |
moveColumn(int columnIndex, int newIndex) Moves the column and heading at columnIndex to
newIndex .
|
void |
Property Change Listener change method. |
protected void |
Recalculates the total combined width of all columns. |
void |
removeColumn(TableColumn column) Deletes the column from the
tableColumns array.
|
void |
Removes a listener for table column model events. |
void |
setColumnMargin(int newMargin) Sets the column margin to newMargin .
|
void |
setColumnSelectionAllowed(boolean flag) Sets whether column selection is allowed. |
void |
setSelectionModel(ListSelectionModel newModel) Sets the selection model for this TableColumnModel
to newModel
and registers for listener notifications from the new selection
model.
|
void |
A ListSelectionListener that forwards
ListSelectionEvents when there is a column
selection change.
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected transient ChangeEvent changeEvent
protected int columnMargin
protected boolean columnSelectionAllowed
protected EventListenerList listenerList
protected ListSelectionModel selectionModel
protected Vector tableColumns
protected int totalColumnWidth
Constructor Detail |
---|
public DefaultTableColumnModel()
Method Detail |
---|
public void addColumn(TableColumn aColumn)
aColumn
to the end of the
tableColumns
array.
This method also posts the columnAdded
event to its listeners.
aColumn
- the TableColumn
to be addedpublic void addColumnModelListener(TableColumnModelListener x)
x
- a TableColumnModelListener
objectprotected ListSelectionModel createSelectionModel()
protected void fireColumnAdded(TableColumnModelEvent e)
e
- the event receivedprotected void fireColumnMarginChanged()
protected void fireColumnMoved(TableColumnModelEvent e)
e
- the event receivedprotected void fireColumnRemoved(TableColumnModelEvent e)
e
- the event receivedprotected void fireColumnSelectionChanged(ListSelectionEvent e)
e
- the event receivedpublic TableColumn getColumn(int columnIndex)
TableColumn
object for the column
at columnIndex
.
columnIndex
- the index of the column desiredTableColumn
object for the column
at columnIndex
public int getColumnCount()
tableColumns
array.
tableColumns
arraypublic int getColumnIndex(Object identifier)
tableColumns
array whose identifier is equal to identifier
,
when compared using equals
.
identifier
- the identifier objecttableColumns
array whose identifier
is equal to identifier
public int getColumnIndexAtX(int x)
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
accomodate 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.
x
- the horizontal location of interestpublic int getColumnMargin()
TableColumn
.
The default columnMargin
is 1.
TableColumn
public TableColumnModelListener[] getColumnModelListeners()
ColumnModelListener
s
or an empty
array if no column model listeners are currently registeredpublic Enumeration getColumns()
Enumeration
of all the columns in the model.
Enumeration
of the columns in the modelpublic boolean getColumnSelectionAllowed()
columnSelectionAllowed
propertypublic EventListener[] getListeners(Class listenerType)
FooListener
s
upon this model.
FooListener
s 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.
listenerType
- the type of listeners requested; this parameter
should specify an interface that descends from
java.util.EventListener
FooListener
s on this model,
or an empty array if no such
listeners have been addedpublic int getSelectedColumnCount()
public int[] getSelectedColumns()
selectionModel
is null
, returns an empty array.
selectionModel
is
null
public ListSelectionModel getSelectionModel()
ListSelectionModel
that is used to
maintain column selection state.
null
if row selection is not allowed.public int getTotalColumnWidth()
totalColumnWidth
propertypublic void moveColumn(int columnIndex, int newIndex)
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.
columnIndex
- the index of column to be movednewIndex
- new index to move the columnpublic void propertyChange(PropertyChangeEvent evt)
evt
- PropertyChangeEvent
protected void recalcWidthCache()
totalColumnWidth
property.
public void removeColumn(TableColumn column)
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.
column
- the TableColumn
to be removedpublic void removeColumnModelListener(TableColumnModelListener x)
x
- a TableColumnModelListener
objectpublic void setColumnMargin(int newMargin)
newMargin
. This method
also posts a columnMarginChanged
event to its
listeners.
newMargin
- the new margin width, in pixelspublic void setColumnSelectionAllowed(boolean flag)
flag
- true if column selection will be allowed, false otherwisepublic void setSelectionModel(ListSelectionModel newModel)
TableColumnModel
to newModel
and registers for listener notifications from the new selection
model. If newModel
is null
,
an exception is thrown.
newModel
- the new selection modelpublic void valueChanged(ListSelectionEvent e)
ListSelectionListener
that forwards
ListSelectionEvents
when there is a column
selection change.
e
- the change event
| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |