Package jmri.util.swing
Class XTableColumnModel
- java.lang.Object
- 
- javax.swing.table.DefaultTableColumnModel
- 
- jmri.util.swing.XTableColumnModel
 
 
- 
- All Implemented Interfaces:
- java.beans.PropertyChangeListener,- java.io.Serializable,- java.util.EventListener,- javax.swing.event.ListSelectionListener,- javax.swing.table.TableColumnModel
 
 public class XTableColumnModel extends javax.swing.table.DefaultTableColumnModel Taken from http://www.stephenkelvin.de/XTableColumnModel/XTableColumnModelextends the DefaultTableColumnModel . It provides a comfortable way to hide/show columns. Columns keep their positions when hidden and shown again.In order to work with JTable it cannot add any events to TableColumnModelListener. Therefore hiding a column will result incolumnRemovedevent and showing it again will notify listeners of acolumnAdded, and possibly acolumnMovedevent. For the same reason the following methods still deal with visible columns only: getColumnCount(), getColumns(), getColumnIndex(), getColumn() There are overloaded versions of these methods that take a parameteronlyVisiblewhich let's you specify whether you want invisible columns taken into account.- See Also:
- DefaultTableColumnModel, Serialized Form
 
- 
- 
Field SummaryFields Modifier and Type Field Description protected java.util.Vector<javax.swing.table.TableColumn>allTableColumnsArray of TableColumn objects in this model.
 - 
Constructor SummaryConstructors Constructor Description XTableColumnModel()Creates an extended table column model.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddColumn(javax.swing.table.TableColumn column)Appendcolumnto the right of existing columns.javax.swing.table.TableColumngetColumn(int columnIndex, boolean onlyVisible)Returns theTableColumnobject for the column atcolumnIndex.javax.swing.table.TableColumngetColumnByModelIndex(int modelColumnIndex)Maps the index of the column in the table model atmodelColumnIndexto the TableColumn object.intgetColumnCount(boolean onlyVisible)Returns the total number of columns in this model.intgetColumnIndex(java.lang.Object identifier, boolean onlyVisible)Returns the position of the first column whose identifier equalsidentifier.java.util.Enumeration<javax.swing.table.TableColumn>getColumns(boolean onlyVisible)Returns anEnumerationof all the columns in the model.booleanisColumnVisible(javax.swing.table.TableColumn aColumn)Checks whether the specified column is currently visible.voidmoveColumn(int columnIndex, int newIndex)Moves the column fromcolumnIndextonewIndex.voidmoveColumn(int columnIndex, int newIndex, boolean onlyVisible)Moves the column fromcolumnIndextonewIndex.voidremoveColumn(javax.swing.table.TableColumn column)Removescolumnfrom this column model.voidsetAllColumnsVisible()Makes all columns in this model visiblevoidsetColumnVisible(javax.swing.table.TableColumn column, boolean visible)Sets the visibility of the specified TableColumn.- 
Methods inherited from class javax.swing.table.DefaultTableColumnModeladdColumnModelListener, createSelectionModel, fireColumnAdded, fireColumnMarginChanged, fireColumnMoved, fireColumnRemoved, fireColumnSelectionChanged, getColumn, getColumnCount, getColumnIndex, getColumnIndexAtX, getColumnMargin, getColumnModelListeners, getColumns, getColumnSelectionAllowed, getListeners, getSelectedColumnCount, getSelectedColumns, getSelectionModel, getTotalColumnWidth, propertyChange, recalcWidthCache, removeColumnModelListener, setColumnMargin, setColumnSelectionAllowed, setSelectionModel, valueChanged
 
- 
 
- 
- 
- 
Field Detail- 
allTableColumnsprotected java.util.Vector<javax.swing.table.TableColumn> allTableColumns Array of TableColumn objects in this model. Holds all column objects, regardless of their visibility
 
- 
 - 
Constructor Detail- 
XTableColumnModelpublic XTableColumnModel() Creates an extended table column model.
 
- 
 - 
Method Detail- 
setColumnVisiblepublic void setColumnVisible(javax.swing.table.TableColumn column, boolean visible) Sets the visibility of the specified TableColumn. The call is ignored if the TableColumn is not found in this column model or its visibility status did not change.- Parameters:
- column- the column to show/hide
- visible- its new visibility status
 
 - 
setAllColumnsVisiblepublic void setAllColumnsVisible() Makes all columns in this model visible
 - 
getColumnByModelIndexpublic javax.swing.table.TableColumn getColumnByModelIndex(int modelColumnIndex) Maps the index of the column in the table model atmodelColumnIndexto the TableColumn object. There may be multiple TableColumn objects showing the same model column, though this is uncommon.- Parameters:
- modelColumnIndex- index of column in table model
- Returns:
- the first column, visible or invisible, with the specified index or null if no such column
 
 - 
isColumnVisiblepublic boolean isColumnVisible(javax.swing.table.TableColumn aColumn) Checks whether the specified column is currently visible.- Parameters:
- aColumn- column to check
- Returns:
- visibility of specified column (false if there is no such column at all. [It's not visible, right?])
 
 - 
addColumnpublic void addColumn(javax.swing.table.TableColumn column) Appendcolumnto the right of existing columns. PostscolumnAddedevent.- Specified by:
- addColumnin interface- javax.swing.table.TableColumnModel
- Overrides:
- addColumnin class- javax.swing.table.DefaultTableColumnModel
- Parameters:
- column- The column to be added
- Throws:
- java.lang.IllegalArgumentException- if- columnis- null
- See Also:
- removeColumn(javax.swing.table.TableColumn)
 
 - 
removeColumnpublic void removeColumn(javax.swing.table.TableColumn column) Removescolumnfrom this column model. PostscolumnRemovedevent. Will do nothing if the column is not in this model.- Specified by:
- removeColumnin interface- javax.swing.table.TableColumnModel
- Overrides:
- removeColumnin class- javax.swing.table.DefaultTableColumnModel
- Parameters:
- column- the column to be added
- See Also:
- addColumn(javax.swing.table.TableColumn)
 
 - 
moveColumnpublic void moveColumn(int columnIndex, int newIndex) Moves the column fromcolumnIndextonewIndex. PostscolumnMovedevent. Will not move any columns ifcolumnIndexequalsnewIndex. This method also posts acolumnMovedevent to its listeners.- Specified by:
- moveColumnin interface- javax.swing.table.TableColumnModel
- Overrides:
- moveColumnin class- javax.swing.table.DefaultTableColumnModel
- Parameters:
- columnIndex- index of column to be moved
- newIndex- new index of the column
- Throws:
- java.lang.IllegalArgumentException- if either- oldIndexor- newIndexare not in [0, getColumnCount() - 1]
 
 - 
moveColumnpublic void moveColumn(int columnIndex, int newIndex, boolean onlyVisible) Moves the column fromcolumnIndextonewIndex. PostscolumnMovedevent. Will not move any columns ifcolumnIndexequalsnewIndex. This method also posts acolumnMovedevent to its listeners if a visible column moves.- Parameters:
- columnIndex- index of column to be moved
- newIndex- new index of the column
- onlyVisible- true if this should only move a visible column; false to move any column
- Throws:
- java.lang.IllegalArgumentException- if either- oldIndexor- newIndexare not in [0, getColumnCount(onlyVisible) - 1]
 
 - 
getColumnCountpublic int getColumnCount(boolean onlyVisible) Returns the total number of columns in this model.- Parameters:
- onlyVisible- if set only visible columns will be counted
- Returns:
- the number of columns in the tableColumnsarray
- See Also:
- getColumns(boolean)
 
 - 
getColumnspublic java.util.Enumeration<javax.swing.table.TableColumn> getColumns(boolean onlyVisible) Returns anEnumerationof all the columns in the model.- Parameters:
- onlyVisible- if set all invisible columns will be missing from the enumeration.
- Returns:
- an Enumerationof the columns in the model
 
 - 
getColumnIndexpublic int getColumnIndex(java.lang.Object identifier, boolean onlyVisible) Returns the position of the first column whose identifier equalsidentifier. Position is the index in all visible columns ifonlyVisibleis true or else the index in all columns.- Parameters:
- identifier- the identifier object to search for
- onlyVisible- if set searches only visible columns
- Returns:
- the index of the first column whose identifier equals
         identifier
- Throws:
- java.lang.IllegalArgumentException- if- identifieris- null, or if no- TableColumnhas this- identifier
- See Also:
- getColumn(int, boolean)
 
 - 
getColumnpublic javax.swing.table.TableColumn getColumn(int columnIndex, boolean onlyVisible) Returns theTableColumnobject for the column atcolumnIndex.- Parameters:
- columnIndex- the index of the column desired
- onlyVisible- if set columnIndex is meant to be relative to all visible columns only else it is the index in all columns
- Returns:
- the TableColumnobject for the column atcolumnIndex
 
 
- 
 
-