Package jadex.commons.gui.jtable
Class VisibilityTableColumnModel
- java.lang.Object
- 
- javax.swing.table.DefaultTableColumnModel
- 
- jadex.commons.gui.jtable.VisibilityTableColumnModel
 
 
- 
- All Implemented Interfaces:
- IVisibilityTableColumnModel,- java.beans.PropertyChangeListener,- java.io.Serializable,- java.util.EventListener,- javax.swing.event.ListSelectionListener,- javax.swing.table.TableColumnModel
 
 public class VisibilityTableColumnModel extends javax.swing.table.DefaultTableColumnModel implements IVisibilityTableColumnModel VisibilityTableColumnModelextends 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 toTableColumnModelListener. 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() If you want to take invisible column into account use: getAllColumnCount(), getAllColumns(), getAllColumnIndex(), getAllColumn()- See Also:
- DefaultTableColumnModel, Serialized Form
 
- 
- 
Field SummaryFields Modifier and Type Field Description protected java.util.VectorallTableColumnsArray of TableColumn objects in this model.protected java.util.VectortableColumnsFixedArray of TableColumn objects that cannot change the visibility.
 - 
Constructor SummaryConstructors Constructor Description VisibilityTableColumnModel()Creates an extended table column model.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddColumn(javax.swing.table.TableColumn column)AppendsaColumnto the end of thetableColumnsarray.voidaddMouseListener(javax.swing.JTable table)Helper method that adds a mouselistener to the header of a givenJTable.javax.swing.table.TableColumngetAllColumn(int columnIndex)Returns theTableColumnobject for the column atcolumnIndex.intgetAllColumnCount()Returns the number of columns in the model.intgetAllColumnIndex(java.lang.Object identifier)Returns the index of the first column in the table whose identifier is equal toidentifier, when compared usingequals.java.util.EnumerationgetAllColumns()Returns anEnumerationof all the columns in the model.booleanisColumnChangeable(javax.swing.table.TableColumn column)Checks whether the specified column can change visibility.booleanisColumnVisible(javax.swing.table.TableColumn aColumn)Checks whether the specified column is currently visible.voidmoveColumn(int columnIndex, int newIndex)Moves the column and its header atcolumnIndextonewIndex.voidremoveColumn(javax.swing.table.TableColumn column)Deletes theTableColumncolumnfrom thetableColumnsarray.voidsetAllColumnsVisible()Makes all columns in this model visiblevoidsetColumnChangeable(javax.swing.table.TableColumn column, boolean changeable)Sets whether this column can change visibility.voidsetColumnVisible(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 allTableColumns Array of TableColumn objects in this model. Holds all column objects, regardless of their visibility
 - 
tableColumnsFixedprotected java.util.Vector tableColumnsFixed Array of TableColumn objects that cannot change the visibility. By default this array is empty
 
- 
 - 
Method Detail- 
addColumnpublic void addColumn(javax.swing.table.TableColumn column) AppendsaColumnto the end of thetableColumnsarray. This method posts acolumnAddedevent to its listeners.- Specified by:
- addColumnin interface- javax.swing.table.TableColumnModel
- Overrides:
- addColumnin class- javax.swing.table.DefaultTableColumnModel
- Parameters:
- column- the- TableColumnto be added
- See Also:
- DefaultTableColumnModel.addColumn(javax.swing.table.TableColumn)
 
 - 
removeColumnpublic void removeColumn(javax.swing.table.TableColumn column) Deletes theTableColumncolumnfrom thetableColumnsarray. This method will do nothing ifcolumnis not in the table's column list. This method posts acolumnRemovedevent to its listeners.- Specified by:
- removeColumnin interface- javax.swing.table.TableColumnModel
- Overrides:
- removeColumnin class- javax.swing.table.DefaultTableColumnModel
- Parameters:
- column- the- TableColumnto be removed
- See Also:
- DefaultTableColumnModel.removeColumn(javax.swing.table.TableColumn)
 
 - 
moveColumnpublic void moveColumn(int columnIndex, int newIndex)Moves the column and its header atcolumnIndextonewIndex. The old column atcolumnIndexwill now be found atnewIndex. The column that used to be atnewIndexis shifted left or right to make room. This will not move any columns ifcolumnIndexequalsnewIndex. This method posts acolumnMovedevent to its listeners.- Specified by:
- moveColumnin interface- javax.swing.table.TableColumnModel
- Overrides:
- moveColumnin class- javax.swing.table.DefaultTableColumnModel
- Parameters:
- columnIndex- the index of column to be moved
- newIndex- index of the column's new location
- Throws:
- java.lang.IllegalArgumentException- if- columnIndexor- newIndexare not in the valid range
- See Also:
- DefaultTableColumnModel.moveColumn(int, int)
 
 - 
getAllColumnCountpublic int getAllColumnCount() Returns the number of columns in the model.
 - Specified by:
- getAllColumnCountin interface- IVisibilityTableColumnModel
- Returns:
- the number of columns in the model
 - 
getAllColumnspublic java.util.Enumeration getAllColumns() Returns anEnumerationof all the columns in the model.
 - Specified by:
- getAllColumnsin interface- IVisibilityTableColumnModel
- Returns:
- an Enumerationof all the columns in the model
 - 
getAllColumnIndexpublic int getAllColumnIndex(java.lang.Object identifier) Returns the index of the first column in the table whose identifier is equal toidentifier, when compared usingequals.
 - Specified by:
- getAllColumnIndexin interface- IVisibilityTableColumnModel
- Parameters:
- identifier- the identifier object
- Returns:
- the index of the first table column
                  whose identifier is equal to identifier
- Throws:
- java.lang.IllegalArgumentException- if- identifieris- null, or no- TableColumnhas this- identifier
- See Also:
- getAllColumn(int)
 - 
getAllColumnpublic javax.swing.table.TableColumn getAllColumn(int columnIndex) Returns theTableColumnobject for the column atcolumnIndex.
 - Specified by:
- getAllColumnin interface- IVisibilityTableColumnModel
- Parameters:
- columnIndex- the index of the desired column
- Returns:
- the TableColumnobject for the column atcolumnIndex
 - 
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. This method posts acolumnAddedorcolumnRemovedevent to its listeners.- Specified by:
- setColumnVisiblein interface- IVisibilityTableColumnModel
- Parameters:
- column- the- TableColumn
- visible- its new visibility status
 
 - 
setAllColumnsVisiblepublic void setAllColumnsVisible() Makes all columns in this model visible- Specified by:
- setAllColumnsVisiblein interface- IVisibilityTableColumnModel
- See Also:
- isColumnVisible(javax.swing.table.TableColumn),- setColumnVisible(javax.swing.table.TableColumn, boolean)
 
 - 
isColumnVisiblepublic boolean isColumnVisible(javax.swing.table.TableColumn aColumn) Checks whether the specified column is currently visible.- Specified by:
- isColumnVisiblein interface- IVisibilityTableColumnModel
- Parameters:
- aColumn- column to check
- Returns:
- visibility of specified column. false if there is no such column at all.
- See Also:
- setAllColumnsVisible(),- setColumnVisible(javax.swing.table.TableColumn, boolean)
 
 - 
setColumnChangeablepublic void setColumnChangeable(javax.swing.table.TableColumn column, boolean changeable)Sets whether this column can change visibility.- Specified by:
- setColumnChangeablein interface- IVisibilityTableColumnModel
- Parameters:
- column- the- TableColumn
- changeable- if true, changing visibility is allowed; otherwise false
 
 - 
isColumnChangeablepublic boolean isColumnChangeable(javax.swing.table.TableColumn column) Checks whether the specified column can change visibility.- Specified by:
- isColumnChangeablein interface- IVisibilityTableColumnModel
- Parameters:
- column- column to check
- Returns:
- true if the column can change visibility; otherwise false
 
 - 
addMouseListenerpublic void addMouseListener(javax.swing.JTable table) Helper method that adds a mouselistener to the header of a givenJTable. On right click a popup menu will appear to change the visibility of the columns in the jtable- Parameters:
- table- the- JTableto add the mouselistener to its header
 
 
 
 
 
 
- 
 
-