public class DefaultTableColumnModel extends Objectimplements TableColumnModel , PropertyChangeListener , ListSelectionListener , Serializable
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 JavaBeans™ has been added to the java.beans package. Please see XMLEncoder.
JTable
| Modifier and Type | Field and Description |
|---|---|
protected 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 and Description |
|---|
DefaultTableColumnModel()
Creates a default table column model.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addColumn(TableColumn
Appends
aColumn to the end of the
tableColumns array.
|
void |
addColumnModelListener(TableColumnModelListener
Adds a listener for table column model events.
|
protected ListSelectionModel |
createSelectionModel()
Creates a new default list selection model.
|
protected void |
fireColumnAdded(TableColumnModelEvent
Notifies all listeners that have registered interest for notification on this event type.
|
protected void |
fireColumnMarginChanged()
Notifies all listeners that have registered interest for notification on this event type.
|
protected void |
fireColumnMoved(TableColumnModelEvent
Notifies all listeners that have registered interest for notification on this event type.
|
protected void |
fireColumnRemoved(TableColumnModelEvent
Notifies all listeners that have registered interest for notification on this event type.
|
protected void |
fireColumnSelectionChanged(ListSelectionEvent
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 |
getColumnCount()
Returns the number of columns in the
tableColumns array.
|
int |
getColumnIndex(Object
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 |
getColumnMargin()
Returns the width margin for
TableColumn.
|
TableColumnModelListener |
getColumnModelListeners()
Returns an array of all the column model listeners registered on this model.
|
Enumeration |
getColumns()
Returns an
Enumeration of all the columns in the model.
|
boolean |
getColumnSelectionAllowed()
Returns true if column selection is allowed, otherwise false.
|
<T extends EventListener |
getListeners(Class
Returns an array of all the objects currently registered as
FooListeners upon this model.
|
int |
getSelectedColumnCount()
Returns the number of columns selected.
|
int[] |
getSelectedColumns()
Returns an array of selected columns.
|
ListSelectionModel |
getSelectionModel()
Returns the
ListSelectionModel that is used to maintain column selection state.
|
int |
getTotalColumnWidth()
Returns the total combined width of all columns.
|
void |
moveColumn(int columnIndex, int newIndex)
Moves the column and heading at
columnIndex to
newIndex.
|
void |
propertyChange(PropertyChangeEvent
Property Change Listener change method.
|
protected void |
recalcWidthCache()
Recalculates the total combined width of all columns.
|
void |
removeColumn(TableColumn
Deletes the
column from the
tableColumns array.
|
void |
removeColumnModelListener(TableColumnModelListener
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
Sets the selection model for this
TableColumnModel to
newModel and registers for listener notifications from the new selection model.
|
void |
valueChanged(ListSelectionEvent
A
ListSelectionListener that forwards
ListSelectionEvents when there is a column selection change.
|
protected Vector<TableColumn > tableColumns
protected ListSelectionModelselectionModel
protected int columnMargin
protected EventListenerListlistenerList
protected transient ChangeEventchangeEvent
protected boolean columnSelectionAllowed
protected int totalColumnWidth
public DefaultTableColumnModel()
public void addColumn(TableColumnaColumn)
aColumn to the end of the
tableColumns array. This method also posts the
columnAdded event to its listeners.
addColumn in interface
TableColumnModel
aColumn - the
TableColumn to be added
IllegalArgumentException - if
aColumn is
null
removeColumn(javax.swing.table.TableColumn)
public void removeColumn(TableColumncolumn)
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.
removeColumn in interface
TableColumnModel
column - the
TableColumn to be removed
addColumn(javax.swing.table.TableColumn)
public 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.
moveColumn in interface
TableColumnModel
columnIndex - the index of column to be moved
newIndex - new index to move the column
IllegalArgumentException - if
column or
newIndex are not in the valid range
public void setColumnMargin(int newMargin)
newMargin. This method also posts a
columnMarginChanged event to its listeners.
setColumnMargin in interface
TableColumnModel
newMargin - the new margin width, in pixels
getColumnMargin(),
getTotalColumnWidth()
public int getColumnCount()
tableColumns array.
getColumnCount in interface
TableColumnModel
tableColumns array
getColumns()
public Enumeration<TableColumn > getColumns()
Enumeration of all the columns in the model.
getColumns in interface
TableColumnModel
Enumeration of the columns in the model
public int getColumnIndex(Objectidentifier)
tableColumns array whose identifier is equal to
identifier, when compared using
equals.
getColumnIndex in interface
TableColumnModel
identifier - the identifier object
tableColumns array whose identifier is equal to
identifier
IllegalArgumentException - if
identifier is
null, or if no
TableColumn has this
identifier
getColumn(int)
public TableColumngetColumn(int columnIndex)
TableColumn object for the column at
columnIndex.
getColumn in interface
TableColumnModel
columnIndex - the index of the column desired
TableColumn object for the column at
columnIndex
public int getColumnMargin()
TableColumn. The default
columnMargin is 1.
getColumnMargin in interface
TableColumnModel
TableColumn
setColumnMargin(int)
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 accommodate 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.
getColumnIndexAtX in interface
TableColumnModel
x - the horizontal location of interest
JTable.columnAtPoint(java.awt.Point)
public int getTotalColumnWidth()
getTotalColumnWidth in interface
TableColumnModel
totalColumnWidth property
public void setSelectionModel(ListSelectionModelnewModel)
TableColumnModel to
newModel and registers for listener notifications from the new selection model. If
newModel is
null, an exception is thrown.
setSelectionModel in interface
TableColumnModel
newModel - the new selection model
IllegalArgumentException - if
newModel is
null
getSelectionModel()
public ListSelectionModelgetSelectionModel()
ListSelectionModel that is used to maintain column selection state.
getSelectionModel in interface
TableColumnModel
null if row selection is not allowed.
setSelectionModel(javax.swing.ListSelectionModel)
public void setColumnSelectionAllowed(boolean flag)
setColumnSelectionAllowed in interface
TableColumnModel
flag - true if column selection will be allowed, false otherwise
TableColumnModel.getColumnSelectionAllowed()
public boolean getColumnSelectionAllowed()
getColumnSelectionAllowed in interface
TableColumnModel
columnSelectionAllowed property
TableColumnModel.setColumnSelectionAllowed(boolean)
public int[] getSelectedColumns()
selectionModel is
null, returns an empty array.
getSelectedColumns in interface
TableColumnModel
selectionModel is
null
public int getSelectedColumnCount()
getSelectedColumnCount in interface
TableColumnModel
public void addColumnModelListener(TableColumnModelListenerx)
addColumnModelListener in interface
TableColumnModel
x - a
TableColumnModelListener object
public void removeColumnModelListener(TableColumnModelListenerx)
removeColumnModelListener in interface
TableColumnModel
x - a
TableColumnModelListener object
public TableColumnModelListener[] getColumnModelListeners()
ColumnModelListeners or an empty array if no column model listeners are currently registered
addColumnModelListener(javax.swing.event.TableColumnModelListener),
removeColumnModelListener(javax.swing.event.TableColumnModelListener)
protected void fireColumnAdded(TableColumnModelEvente)
e - the event received
EventListenerList
protected void fireColumnRemoved(TableColumnModelEvente)
e - the event received
EventListenerList
protected void fireColumnMoved(TableColumnModelEvente)
e - the event received
EventListenerList
protected void fireColumnSelectionChanged(ListSelectionEvente)
e - the event received
EventListenerList
protected void fireColumnMarginChanged()
EventListenerList
public <T extends EventListener> T[] getListeners(Class <T> listenerType)
FooListeners upon this model.
FooListeners 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
FooListeners on this model, or an empty array if no such listeners have been added
ClassCastException - if
listenerType doesn't specify a class or interface that implements
java.util.EventListener
getColumnModelListeners()
public void propertyChange(PropertyChangeEventevt)
propertyChange in interface
PropertyChangeListener
evt -
PropertyChangeEvent
public void valueChanged(ListSelectionEvente)
ListSelectionListener that forwards
ListSelectionEvents when there is a column selection change.
valueChanged in interface
ListSelectionListener
e - the change event
protected ListSelectionModelcreateSelectionModel()
protected void recalcWidthCache()
totalColumnWidth property.