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 Summary
Fields 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 Summary
Constructors Constructor Description VisibilityTableColumnModel()Creates an extended table column model.
-
Method Summary
All 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.DefaultTableColumnModel
addColumnModelListener, 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
-
allTableColumns
protected java.util.Vector allTableColumns
Array of TableColumn objects in this model. Holds all column objects, regardless of their visibility
-
tableColumnsFixed
protected java.util.Vector tableColumnsFixed
Array of TableColumn objects that cannot change the visibility. By default this array is empty
-
-
Method Detail
-
addColumn
public void addColumn(javax.swing.table.TableColumn column)
AppendsaColumnto the end of thetableColumnsarray. This method posts acolumnAddedevent to its listeners.- Specified by:
addColumnin interfacejavax.swing.table.TableColumnModel- Overrides:
addColumnin classjavax.swing.table.DefaultTableColumnModel- Parameters:
column- theTableColumnto be added- See Also:
DefaultTableColumnModel.addColumn(javax.swing.table.TableColumn)
-
removeColumn
public 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 interfacejavax.swing.table.TableColumnModel- Overrides:
removeColumnin classjavax.swing.table.DefaultTableColumnModel- Parameters:
column- theTableColumnto be removed- See Also:
DefaultTableColumnModel.removeColumn(javax.swing.table.TableColumn)
-
moveColumn
public 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 interfacejavax.swing.table.TableColumnModel- Overrides:
moveColumnin classjavax.swing.table.DefaultTableColumnModel- Parameters:
columnIndex- the index of column to be movednewIndex- index of the column's new location- Throws:
java.lang.IllegalArgumentException- ifcolumnIndexornewIndexare not in the valid range- See Also:
DefaultTableColumnModel.moveColumn(int, int)
-
getAllColumnCount
public int getAllColumnCount()
Returns the number of columns in the model.
- Specified by:
getAllColumnCountin interfaceIVisibilityTableColumnModel- Returns:
- the number of columns in the model
-
getAllColumns
public java.util.Enumeration getAllColumns()
Returns anEnumerationof all the columns in the model.
- Specified by:
getAllColumnsin interfaceIVisibilityTableColumnModel- Returns:
- an
Enumerationof all the columns in the model
-
getAllColumnIndex
public 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 interfaceIVisibilityTableColumnModel- Parameters:
identifier- the identifier object- Returns:
- the index of the first table column
whose identifier is equal to
identifier - Throws:
java.lang.IllegalArgumentException- ifidentifierisnull, or noTableColumnhas thisidentifier- See Also:
getAllColumn(int)
-
getAllColumn
public javax.swing.table.TableColumn getAllColumn(int columnIndex)
Returns theTableColumnobject for the column atcolumnIndex.
- Specified by:
getAllColumnin interfaceIVisibilityTableColumnModel- Parameters:
columnIndex- the index of the desired column- Returns:
- the
TableColumnobject for the column atcolumnIndex
-
setColumnVisible
public 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 interfaceIVisibilityTableColumnModel- Parameters:
column- theTableColumnvisible- its new visibility status
-
setAllColumnsVisible
public void setAllColumnsVisible()
Makes all columns in this model visible- Specified by:
setAllColumnsVisiblein interfaceIVisibilityTableColumnModel- See Also:
isColumnVisible(javax.swing.table.TableColumn),setColumnVisible(javax.swing.table.TableColumn, boolean)
-
isColumnVisible
public boolean isColumnVisible(javax.swing.table.TableColumn aColumn)
Checks whether the specified column is currently visible.- Specified by:
isColumnVisiblein interfaceIVisibilityTableColumnModel- 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)
-
setColumnChangeable
public void setColumnChangeable(javax.swing.table.TableColumn column, boolean changeable)Sets whether this column can change visibility.- Specified by:
setColumnChangeablein interfaceIVisibilityTableColumnModel- Parameters:
column- theTableColumnchangeable- if true, changing visibility is allowed; otherwise false
-
isColumnChangeable
public boolean isColumnChangeable(javax.swing.table.TableColumn column)
Checks whether the specified column can change visibility.- Specified by:
isColumnChangeablein interfaceIVisibilityTableColumnModel- Parameters:
column- column to check- Returns:
- true if the column can change visibility; otherwise false
-
addMouseListener
public 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- theJTableto add the mouselistener to its header
-
-