|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjavax.swing.table.DefaultTableColumnModel
public class DefaultTableColumnModel
A model that stores information about the columns used in a JTable.
JTable.setColumnModel(TableColumnModel),
Serialized Form| Field Summary | |
|---|---|
protected ChangeEvent |
changeEvent
A change event used when notifying listeners of a change to the columnMargin field. |
protected int |
columnMargin
The space between the columns (the default value is 1). |
protected boolean |
columnSelectionAllowed
A flag that indicates whether or not columns can be selected. |
protected EventListenerList |
listenerList
Storage for the listeners registered with the model. |
protected ListSelectionModel |
selectionModel
A selection model that keeps track of column selections. |
protected Vector<TableColumn> |
tableColumns
Storage for the table columns. |
protected int |
totalColumnWidth
The total width of all the columns in this model. |
| Constructor Summary | |
|---|---|
DefaultTableColumnModel()
Creates a new table column model with zero columns. |
|
| Method Summary | ||
|---|---|---|
void |
addColumn(TableColumn column)
Adds a column to the model then calls fireColumnAdded(TableColumnModelEvent) to notify the registered
listeners. |
|
void |
addColumnModelListener(TableColumnModelListener listener)
Registers a listener with the model, so that it will receive TableColumnModelEvent notifications. |
|
protected ListSelectionModel |
createSelectionModel()
Creates a default selection model to track the currently selected column(s). |
|
protected void |
fireColumnAdded(TableColumnModelEvent e)
Sends the specified TableColumnModelEvent to all registered
listeners, to indicate that a column has been added to the model. |
|
protected void |
fireColumnMarginChanged()
Sends a ChangeEvent to the model's registered listeners to
indicate that the column margin was changed. |
|
protected void |
fireColumnMoved(TableColumnModelEvent e)
Sends the specified TableColumnModelEvent to all registered
listeners, to indicate that a column in the model has been moved. |
|
protected void |
fireColumnRemoved(TableColumnModelEvent e)
Sends the specified TableColumnModelEvent to all registered
listeners, to indicate that a column has been removed from the model. |
|
protected void |
fireColumnSelectionChanged(ListSelectionEvent e)
Sends the specified ListSelectionEvent to all registered listeners,
to indicate that the column selections have changed. |
|
TableColumn |
getColumn(int columnIndex)
Returns the column at the specified index. |
|
int |
getColumnCount()
Returns the number of columns in the model. |
|
int |
getColumnIndex(Object identifier)
Returns the index of the TableColumn with the given identifier. |
|
int |
getColumnIndexAtX(int x)
Returns the index of the column that contains the specified x-coordinate. |
|
int |
getColumnMargin()
Returns the column margin. |
|
TableColumnModelListener[] |
getColumnModelListeners()
Returns an array containing the listeners that are registered with the model. |
|
Enumeration<TableColumn> |
getColumns()
Returns an enumeration of the columns in the model. |
|
boolean |
getColumnSelectionAllowed()
Returns true if column selection is allowed, and
false if column selection is not allowed. |
|
|
getListeners(Class<T> listenerType)
Returns an array containing the listeners (of the specified type) that are registered with this model. |
|
int |
getSelectedColumnCount()
Returns the number of selected columns in the model. |
|
int[] |
getSelectedColumns()
Returns an array containing the indices of the selected columns. |
|
ListSelectionModel |
getSelectionModel()
Returns the selection model used to track table column selections. |
|
int |
getTotalColumnWidth()
Returns total width of all the columns in the model, ignoring the columnMargin. |
|
void |
moveColumn(int i,
int j)
Moves the column at index i to the position specified by index j, then calls fireColumnMoved(TableColumnModelEvent) to notify registered
listeners. |
|
void |
propertyChange(PropertyChangeEvent event)
Receives notification of property changes for the columns in the model. |
|
protected void |
recalcWidthCache()
Recalculates the total width of the columns, if the cached value is -1. |
|
void |
removeColumn(TableColumn column)
Removes a column from the model then calls fireColumnRemoved(TableColumnModelEvent) to notify the registered
listeners. |
|
void |
removeColumnModelListener(TableColumnModelListener listener)
Deregisters a listener so that it no longer receives notification of changes to this model. |
|
void |
setColumnMargin(int margin)
Sets the column margin then calls fireColumnMarginChanged() to
notify the registered listeners. |
|
void |
setColumnSelectionAllowed(boolean flag)
Sets the flag that indicates whether or not column selection is allowed. |
|
void |
setSelectionModel(ListSelectionModel model)
Sets the selection model that will be used to keep track of the selected columns. |
|
void |
valueChanged(ListSelectionEvent e)
Receives notification of the change to the list selection model, and responds by calling fireColumnSelectionChanged(ListSelectionEvent). |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected Vector<TableColumn> tableColumns
protected ListSelectionModel selectionModel
protected int columnMargin
1).
protected EventListenerList listenerList
protected transient ChangeEvent changeEvent
columnMargin field. This single event is reused for all
notifications (it is lazily instantiated within the
fireColumnMarginChanged() method).
protected boolean columnSelectionAllowed
protected int totalColumnWidth
| Constructor Detail |
|---|
public DefaultTableColumnModel()
createSelectionModel().
The default value for columnMargin is 1 and
the default value for columnSelectionAllowed is
false.
| Method Detail |
|---|
public void addColumn(TableColumn column)
fireColumnAdded(TableColumnModelEvent) to notify the registered
listeners. The model registers itself with the column as a
PropertyChangeListener so that changes to the column width will
invalidate the cached totalColumnWidth value.
addColumn in interface TableColumnModelcolumn - the column (null not permitted).
IllegalArgumentException - if column is
null.removeColumn(TableColumn)public void removeColumn(TableColumn column)
fireColumnRemoved(TableColumnModelEvent) to notify the registered
listeners. If the specified column does not belong to the model, or is
null, this method does nothing.
removeColumn in interface TableColumnModelcolumn - the column to be removed (null permitted).addColumn(TableColumn)
public void moveColumn(int i,
int j)
fireColumnMoved(TableColumnModelEvent) to notify registered
listeners.
moveColumn in interface TableColumnModeli - index of the column that will be moved.j - index of the column's new location.
IllegalArgumentException - if i or j are
outside the range 0 to N-1, where
N is the column count.public void setColumnMargin(int margin)
fireColumnMarginChanged() to
notify the registered listeners.
setColumnMargin in interface TableColumnModelmargin - the column margin.getColumnMargin()public int getColumnCount()
getColumnCount in interface TableColumnModelpublic Enumeration<TableColumn> getColumns()
getColumns in interface TableColumnModelpublic int getColumnIndex(Object identifier)
TableColumn with the given identifier.
getColumnIndex in interface TableColumnModelidentifier - the identifier (null not permitted).
TableColumn with the given identifier.
IllegalArgumentException - if identifier is
null or there is no column with that identifier.public TableColumn getColumn(int columnIndex)
getColumn in interface TableColumnModelcolumnIndex - the column index (in the range from 0 to
N-1, where N is the number of columns in
the model).
ArrayIndexOutOfBoundsException - if i is not within
the specified range.public int getColumnMargin()
getColumnMargin in interface TableColumnModelsetColumnMargin(int)public int getColumnIndexAtX(int x)
-1.
getColumnIndexAtX in interface TableColumnModelx - the x-position.
-1.public int getTotalColumnWidth()
columnMargin.
getTotalColumnWidth in interface TableColumnModelpublic void setSelectionModel(ListSelectionModel model)
setSelectionModel in interface TableColumnModelmodel - the selection model (null not permitted).
IllegalArgumentException - if model is
null.getSelectionModel()public ListSelectionModel getSelectionModel()
getSelectionModel in interface TableColumnModelsetSelectionModel(ListSelectionModel)public void setColumnSelectionAllowed(boolean flag)
setColumnSelectionAllowed in interface TableColumnModelflag - the new flag value.getColumnSelectionAllowed()public boolean getColumnSelectionAllowed()
true if column selection is allowed, and
false if column selection is not allowed.
getColumnSelectionAllowed in interface TableColumnModelsetColumnSelectionAllowed(boolean)public int[] getSelectedColumns()
getSelectedColumns in interface TableColumnModelpublic int getSelectedColumnCount()
getSelectedColumnCount in interface TableColumnModelgetSelectionModel()public void addColumnModelListener(TableColumnModelListener listener)
TableColumnModelEvent notifications.
addColumnModelListener in interface TableColumnModellistener - the listener (null ignored).public void removeColumnModelListener(TableColumnModelListener listener)
removeColumnModelListener in interface TableColumnModellistener - the listener to removepublic TableColumnModelListener[] getColumnModelListeners()
addColumnModelListener(TableColumnModelListener)protected void fireColumnAdded(TableColumnModelEvent e)
TableColumnModelEvent to all registered
listeners, to indicate that a column has been added to the model. The
event's toIndex attribute should contain the index of the
added column.
e - the event.addColumn(TableColumn)protected void fireColumnRemoved(TableColumnModelEvent e)
TableColumnModelEvent to all registered
listeners, to indicate that a column has been removed from the model. The
event's fromIndex attribute should contain the index of the
removed column.
e - the event.removeColumn(TableColumn)protected void fireColumnMoved(TableColumnModelEvent e)
TableColumnModelEvent to all registered
listeners, to indicate that a column in the model has been moved. The
event's fromIndex attribute should contain the old column
index, and the toIndex attribute should contain the new
column index.
e - the event.moveColumn(int, int)protected void fireColumnSelectionChanged(ListSelectionEvent e)
ListSelectionEvent to all registered listeners,
to indicate that the column selections have changed.
e - the event.valueChanged(ListSelectionEvent)protected void fireColumnMarginChanged()
ChangeEvent to the model's registered listeners to
indicate that the column margin was changed.
setColumnMargin(int)public <T extends EventListener> T[] getListeners(Class<T> listenerType)
listenerType - the listener type (must indicate a subclass of
EventListener, null not permitted).
public void propertyChange(PropertyChangeEvent event)
width property for any column changes, we invalidate
the totalColumnWidth value here.
propertyChange in interface PropertyChangeListenerevent - the event.public void valueChanged(ListSelectionEvent e)
fireColumnSelectionChanged(ListSelectionEvent).
valueChanged in interface ListSelectionListenere - the list selection event.getSelectionModel()protected ListSelectionModel createSelectionModel()
DefaultListSelectionModel.
protected void recalcWidthCache()
-1. Otherwise this method does nothing.
getTotalColumnWidth()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||