public class DefaultTableColumnModel extends Object implements 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 JavaBeansTM
 has been added to the java.beans package.
 Please see XMLEncoder.
JTable| Modifier and Type | Field and Description | 
|---|---|
| protected ChangeEvent | changeEventChange event (only one needed) | 
| protected int | columnMarginWidth margin between each column | 
| protected boolean | columnSelectionAllowedColumn selection allowed in this column model | 
| protected EventListenerList | listenerListList of TableColumnModelListener | 
| protected ListSelectionModel | selectionModelModel for keeping track of column selections | 
| protected Vector<TableColumn> | tableColumnsArray of TableColumn objects in this model | 
| protected int | totalColumnWidthA 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 aColumn)Appends  aColumnto the end of thetableColumnsarray. | 
| void | addColumnModelListener(TableColumnModelListener x)Adds a listener for table column model events. | 
| protected ListSelectionModel | createSelectionModel()Creates a new default list selection model. | 
| protected void | fireColumnAdded(TableColumnModelEvent e)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 e)Notifies all listeners that have registered interest for
 notification on this event type. | 
| protected void | fireColumnRemoved(TableColumnModelEvent e)Notifies all listeners that have registered interest for
 notification on this event type. | 
| protected void | fireColumnSelectionChanged(ListSelectionEvent e)Notifies all listeners that have registered interest for
 notification on this event type. | 
| TableColumn | getColumn(int columnIndex)Returns the  TableColumnobject for the column
 atcolumnIndex. | 
| int | getColumnCount()Returns the number of columns in the  tableColumnsarray. | 
| int | getColumnIndex(Object identifier)Returns the index of the first column in the  tableColumnsarray whose identifier is equal toidentifier,
 when compared usingequals. | 
| 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<TableColumn> | getColumns()Returns an  Enumerationof all the columns in the model. | 
| boolean | getColumnSelectionAllowed()Returns true if column selection is allowed, otherwise false. | 
| <T extends EventListener>  | getListeners(Class<T> listenerType)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  ListSelectionModelthat 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  columnIndextonewIndex. | 
| void | propertyChange(PropertyChangeEvent evt)Property Change Listener change method. | 
| protected void | recalcWidthCache()Recalculates the total combined width of all columns. | 
| void | removeColumn(TableColumn column)Deletes the  columnfrom thetableColumnsarray. | 
| void | removeColumnModelListener(TableColumnModelListener x)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  TableColumnModeltonewModeland registers for listener notifications from the new selection
  model. | 
| void | valueChanged(ListSelectionEvent e)A  ListSelectionListenerthat forwardsListSelectionEventswhen there is a column
 selection change. | 
protected Vector<TableColumn> tableColumns
protected ListSelectionModel selectionModel
protected int columnMargin
protected EventListenerList listenerList
protected transient ChangeEvent changeEvent
protected boolean columnSelectionAllowed
protected int totalColumnWidth
public DefaultTableColumnModel()
public void addColumn(TableColumn aColumn)
aColumn to the end of the
  tableColumns array.
  This method also posts the columnAdded
  event to its listeners.addColumn in interface TableColumnModelaColumn - the TableColumn to be addedIllegalArgumentException - if aColumn is
                          nullremoveColumn(javax.swing.table.TableColumn)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.removeColumn in interface TableColumnModelcolumn - the TableColumn to be removedaddColumn(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 TableColumnModelcolumnIndex - the index of column to be movednewIndex - new index to move the columnIllegalArgumentException - if column or
                                          newIndex
                                          are not in the valid rangepublic void setColumnMargin(int newMargin)
newMargin.  This method
 also posts a columnMarginChanged event to its
 listeners.setColumnMargin in interface TableColumnModelnewMargin - the new margin width, in pixelsgetColumnMargin(), 
getTotalColumnWidth()public int getColumnCount()
tableColumns array.getColumnCount in interface TableColumnModeltableColumns arraygetColumns()public Enumeration<TableColumn> getColumns()
Enumeration of all the columns in the model.getColumns in interface TableColumnModelEnumeration of the columns in the modelpublic int getColumnIndex(Object identifier)
tableColumns
 array whose identifier is equal to identifier,
 when compared using equals.getColumnIndex in interface TableColumnModelidentifier - the identifier objecttableColumns array whose identifier
                  is equal to identifierIllegalArgumentException - if identifier
                          is null, or if no
                          TableColumn has this
                          identifiergetColumn(int)public TableColumn getColumn(int columnIndex)
TableColumn object for the column
 at columnIndex.getColumn in interface TableColumnModelcolumnIndex - the index of the column desiredTableColumn object for the column
                          at columnIndexpublic int getColumnMargin()
TableColumn.
 The default columnMargin is 1.getColumnMargin in interface TableColumnModelTableColumnsetColumnMargin(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
 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.getColumnIndexAtX in interface TableColumnModelx - the horizontal location of interestJTable.columnAtPoint(java.awt.Point)public int getTotalColumnWidth()
getTotalColumnWidth in interface TableColumnModeltotalColumnWidth propertypublic 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.setSelectionModel in interface TableColumnModelnewModel - the new selection modelIllegalArgumentException - if newModel
                                          is nullgetSelectionModel()public ListSelectionModel getSelectionModel()
ListSelectionModel that is used to
 maintain column selection state.getSelectionModel in interface TableColumnModelnull if row selection is not allowed.setSelectionModel(javax.swing.ListSelectionModel)public void setColumnSelectionAllowed(boolean flag)
setColumnSelectionAllowed in interface TableColumnModelflag - true if column selection will be allowed, false otherwiseTableColumnModel.getColumnSelectionAllowed()public boolean getColumnSelectionAllowed()
getColumnSelectionAllowed in interface TableColumnModelcolumnSelectionAllowed propertyTableColumnModel.setColumnSelectionAllowed(boolean)public int[] getSelectedColumns()
selectionModel
 is null, returns an empty array.getSelectedColumns in interface TableColumnModelselectionModel is
                  nullpublic int getSelectedColumnCount()
getSelectedColumnCount in interface TableColumnModelpublic void addColumnModelListener(TableColumnModelListener x)
addColumnModelListener in interface TableColumnModelx - a TableColumnModelListener objectpublic void removeColumnModelListener(TableColumnModelListener x)
removeColumnModelListener in interface TableColumnModelx - a TableColumnModelListener objectpublic TableColumnModelListener[] getColumnModelListeners()
ColumnModelListeners
         or an empty
         array if no column model listeners are currently registeredaddColumnModelListener(javax.swing.event.TableColumnModelListener), 
removeColumnModelListener(javax.swing.event.TableColumnModelListener)protected void fireColumnAdded(TableColumnModelEvent e)
e - the event receivedEventListenerListprotected void fireColumnRemoved(TableColumnModelEvent e)
e - the event receivedEventListenerListprotected void fireColumnMoved(TableColumnModelEvent e)
e - the event receivedEventListenerListprotected void fireColumnSelectionChanged(ListSelectionEvent e)
e - the event receivedEventListenerListprotected void fireColumnMarginChanged()
EventListenerListpublic <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.EventListenerFooListeners on this model,
          or an empty array if no such
          listeners have been addedClassCastException - if listenerType
          doesn't specify a class or interface that implements
          java.util.EventListenergetColumnModelListeners()public void propertyChange(PropertyChangeEvent evt)
propertyChange in interface PropertyChangeListenerevt - PropertyChangeEventpublic void valueChanged(ListSelectionEvent e)
ListSelectionListener that forwards
 ListSelectionEvents when there is a column
 selection change.valueChanged in interface ListSelectionListenere - the change eventprotected ListSelectionModel createSelectionModel()
protected void recalcWidthCache()
totalColumnWidth property. Submit a bug or feature 
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
 Copyright © 1993, 2014, Oracle and/or its affiliates.  All rights reserved.