Spec-Zone .ru
спецификации, руководства, описания, API
JavaTM 2 Platform
Standard Edition

javax.swing.table
Class DefaultTableColumnModel

java.lang.Object
  |
  +--javax.swing.table.DefaultTableColumnModel

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. A future release of Swing will provide support for long term persistence.

See Also:
JTable, Serialized Form

Field Summary
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 Summary
DefaultTableColumnModel()
          Creates a default table column model.
 
Method Summary
 void addColumn(TableColumn aColumn)
          Appends aColumn to the end of the receiver's tableColumns array.
 void addColumnModelListener(TableColumnModelListener x)
          Add a listener for table column model events.
protected  ListSelectionModel createSelectionModel()
           
protected  void fireColumnAdded(TableColumnModelEvent e)
           
protected  void fireColumnMarginChanged()
           
protected  void fireColumnMoved(TableColumnModelEvent e)
           
protected  void fireColumnRemoved(TableColumnModelEvent e)
           
protected  void fireColumnSelectionChanged(ListSelectionEvent e)
           
 TableColumn getColumn(int columnIndex)
          Returns the TableColumn object for the column at columnIndex
 int getColumnCount()
          Returns the number of columns in the receiver's table columns array.
 int getColumnIndex(Object identifier)
          Returns the index of the first column in the receiver's columns array whose identifier is equal to identifier, when compared using equals().
 int getColumnIndexAtX(int xPosition)
          Returns the index of the column that lies on the xPosition, or -1 if it lies outside the any of the column's bounds.
 int getColumnMargin()
          Returns the width margin for TableColumn.
 Enumeration getColumns()
          Returns an Enumeration of all the columns in the model
 boolean getColumnSelectionAllowed()
          Returns true if columns can be selected.
 int getSelectedColumnCount()
          Returns the number of selected columns.
 int[] getSelectedColumns()
          Returns an array of indexes for selected columns
 ListSelectionModel getSelectionModel()
          Returns the ListSelectionModel that is used to maintain column selection state.
 int getTotalColumnWidth()
          Returns the total width of all the columns.
 void moveColumn(int columnIndex, int newIndex)
          Moves the column and heading at columnIndex to newIndex.
 void propertyChange(PropertyChangeEvent evt)
          This method gets called when a bound property is changed.
protected  void recalcWidthCache()
           
 void removeColumn(TableColumn column)
          Deletes the TableColumn column from the receiver's table columns array.
 void removeColumnModelListener(TableColumnModelListener x)
          Remove a listener for table column model events.
 void setColumnMargin(int newMargin)
          Sets the column margin to newMargin.
 void setColumnSelectionAllowed(boolean flag)
          Sets whether the columns in this model can be selected.
 void setSelectionModel(ListSelectionModel newModel)
          Sets the selection model for this TableColumnModel to newModel and registers with for listner notifications from the new selection model.
 void valueChanged(ListSelectionEvent e)
          Called whenever the value of the selection changes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tableColumns

protected Vector tableColumns
Array of TableColumn objects in this model

selectionModel

protected ListSelectionModel selectionModel
Model for keeping track of column selections

columnMargin

protected int columnMargin
Width margin between each column

listenerList

protected EventListenerList listenerList
List of TableColumnModelListener

changeEvent

protected transient ChangeEvent changeEvent
Change event (only one needed)

columnSelectionAllowed

protected boolean columnSelectionAllowed
Column selection allowed in this column model

totalColumnWidth

protected int totalColumnWidth
A local cache of the combined width of all columns
Constructor Detail

DefaultTableColumnModel

public DefaultTableColumnModel()
Creates a default table column model.
Method Detail

addColumn

public void addColumn(TableColumn aColumn)
Appends aColumn to the end of the receiver's tableColumns array. This method also posts the columnAdded() event to its listeners.
Specified by:
addColumn in interface TableColumnModel
Parameters:
column - The TableColumn to be added
Throws:
IllegalArgumentException - if aColumn is null
See Also:
removeColumn(javax.swing.table.TableColumn)

removeColumn

public void removeColumn(TableColumn column)
Deletes the TableColumn column from the receiver's table columns 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 the columnRemoved() event to its listeners.
Specified by:
removeColumn in interface TableColumnModel
Parameters:
column - The TableColumn to be removed
See Also:
addColumn(javax.swing.table.TableColumn)

moveColumn

public void moveColumn(int columnIndex,
                       int newIndex)
Moves the column and heading at 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 the columnMoved() event to its listeners.
Specified by:
moveColumn in interface TableColumnModel
Parameters:
columnIndex - the index of column to be moved
newIndex - New index to move the column
Throws:
IllegalArgumentException - if column or newIndex are not in the valid range

setColumnMargin

public void setColumnMargin(int newMargin)
Sets the column margin to newMargin. This method also posts the columnMarginChanged() event to its listeners.
Specified by:
setColumnMargin in interface TableColumnModel
Parameters:
newMargin - the width margin of the column
See Also:
getColumnMargin(), getTotalColumnWidth()

getColumnCount

public int getColumnCount()
Returns the number of columns in the receiver's table columns array.
Specified by:
getColumnCount in interface TableColumnModel
Returns:
the number of columns in the receiver's table columns array
See Also:
getColumns()

getColumns

public Enumeration getColumns()
Returns an Enumeration of all the columns in the model
Specified by:
getColumns in interface TableColumnModel

getColumnIndex

public int getColumnIndex(Object identifier)
Returns the index of the first column in the receiver's columns array whose identifier is equal to identifier, when compared using equals().
Specified by:
getColumnIndex in interface TableColumnModel
Parameters:
identifier - the identifier object
Returns:
the index of the first table column in the receiver's tableColumns array whose identifier is equal to identifier, when compared using equals().
Throws:
IllegalArgumentException - if identifier is null or no TableColumn has this identifier
See Also:
getColumn(int)

getColumn

public TableColumn getColumn(int columnIndex)
Returns the TableColumn object for the column at columnIndex
Specified by:
getColumn in interface TableColumnModel
Parameters:
columnIndex - the index of the column desired
Returns:
the TableColumn object for the column at columnIndex

getColumnMargin

public int getColumnMargin()
Returns the width margin for TableColumn. The default columnMargin is 1.
Specified by:
getColumnMargin in interface TableColumnModel
Returns:
the maximum width for the TableColumn.
See Also:
setColumnMargin(int)

getColumnIndexAtX

public int getColumnIndexAtX(int xPosition)
Returns the index of the column that lies on the xPosition, or -1 if it lies outside the any of the column's bounds.
Specified by:
getColumnIndexAtX in interface TableColumnModel
Returns:
the index of the column or -1 if no column is found

getTotalColumnWidth

public int getTotalColumnWidth()
Description copied from interface: TableColumnModel
Returns the total width of all the columns.
Specified by:
getTotalColumnWidth in interface TableColumnModel

setSelectionModel

public void setSelectionModel(ListSelectionModel newModel)
Sets the selection model for this TableColumnModel to newModel and registers with for listner notifications from the new selection model. If newModel is null, it means columns are not selectable.
Specified by:
setSelectionModel in interface TableColumnModel
Parameters:
newModel - the new selection model
Throws:
IllegalArgumentException - if newModel is null
See Also:
getSelectionModel()

getSelectionModel

public ListSelectionModel getSelectionModel()
Returns the ListSelectionModel that is used to maintain column selection state.
Specified by:
getSelectionModel in interface TableColumnModel
Returns:
the object that provides column selection state. Or null if row selection is not allowed.
See Also:
#setSelectionModel()

setColumnSelectionAllowed

public void setColumnSelectionAllowed(boolean flag)
Description copied from interface: TableColumnModel
Sets whether the columns in this model can be selected.
Specified by:
setColumnSelectionAllowed in interface TableColumnModel
Tags copied from interface: TableColumnModel
See Also:
TableColumnModel.getColumnSelectionAllowed()

getColumnSelectionAllowed

public boolean getColumnSelectionAllowed()
Description copied from interface: TableColumnModel
Returns true if columns can be selected.
Specified by:
getColumnSelectionAllowed in interface TableColumnModel
Tags copied from interface: TableColumnModel
Returns:
true if columns can be selected
See Also:
TableColumnModel.setColumnSelectionAllowed(boolean)

getSelectedColumns

public int[] getSelectedColumns()
Description copied from interface: TableColumnModel
Returns an array of indexes for selected columns
Specified by:
getSelectedColumns in interface TableColumnModel
Tags copied from interface: TableColumnModel
Returns:
an array of ints giving the indexes of all selected columns, or an empty int array if no column is selected.

getSelectedColumnCount

public int getSelectedColumnCount()
Description copied from interface: TableColumnModel
Returns the number of selected columns.
Specified by:
getSelectedColumnCount in interface TableColumnModel
Tags copied from interface: TableColumnModel
Returns:
the number of selected columns, or 0 if no columns are selected

addColumnModelListener

public void addColumnModelListener(TableColumnModelListener x)
Description copied from interface: TableColumnModel
Add a listener for table column model events.
Specified by:
addColumnModelListener in interface TableColumnModel
Tags copied from interface: TableColumnModel
Parameters:
x - a TableColumnModelListener object

removeColumnModelListener

public void removeColumnModelListener(TableColumnModelListener x)
Description copied from interface: TableColumnModel
Remove a listener for table column model events.
Specified by:
removeColumnModelListener in interface TableColumnModel
Tags copied from interface: TableColumnModel
Parameters:
x - a TableColumnModelListener object

fireColumnAdded

protected void fireColumnAdded(TableColumnModelEvent e)

fireColumnRemoved

protected void fireColumnRemoved(TableColumnModelEvent e)

fireColumnMoved

protected void fireColumnMoved(TableColumnModelEvent e)

fireColumnSelectionChanged

protected void fireColumnSelectionChanged(ListSelectionEvent e)

fireColumnMarginChanged

protected void fireColumnMarginChanged()

propertyChange

public void propertyChange(PropertyChangeEvent evt)
Description copied from interface: PropertyChangeListener
This method gets called when a bound property is changed.
Specified by:
propertyChange in interface PropertyChangeListener
Tags copied from interface: PropertyChangeListener
Parameters:
evt - A PropertyChangeEvent object describing the event source and the property that has changed.

valueChanged

public void valueChanged(ListSelectionEvent e)
Description copied from interface: ListSelectionListener
Called whenever the value of the selection changes.
Specified by:
valueChanged in interface ListSelectionListener
Tags copied from interface: ListSelectionListener
Parameters:
e - the event that characterizes the change.

createSelectionModel

protected ListSelectionModel createSelectionModel()

recalcWidthCache

protected void recalcWidthCache()

JavaTM 2 Platform
Standard Edition

Submit a bug or feature
Java, Java 2D, and JDBC are a trademarks or registered trademarks of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1999 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.