Package ucar.ui.table
Class HidableTableColumnModel
- java.lang.Object
-
- javax.swing.table.DefaultTableColumnModel
-
- ucar.ui.table.HidableTableColumnModel
-
- All Implemented Interfaces:
PropertyChangeListener,Serializable,EventListener,ListSelectionListener,TableModelListener,TableColumnModel
public class HidableTableColumnModel extends DefaultTableColumnModel implements TableModelListener
HidableTableColumnModelextends 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() There are overloaded versions of these methods that take a parameteronlyVisiblewhich let's you specify whether you want invisible columns taken into account.
-
-
Field Summary
Fields Modifier and Type Field Description protected Vector<TableColumn>allTableColumnsArray of TableColumn objects in this model.-
Fields inherited from class javax.swing.table.DefaultTableColumnModel
changeEvent, columnMargin, columnSelectionAllowed, listenerList, selectionModel, tableColumns, totalColumnWidth
-
-
Constructor Summary
Constructors Constructor Description HidableTableColumnModel(TableModel model)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddColumn(TableColumn column)Appendcolumnto the right of exisiting columns.voidcreateColumnsFromModel(TableModel newModel)TableColumngetColumn(int columnIndex, boolean onlyVisible)Returns theTableColumnobject for the column atcolumnIndex.intgetColumnCount(boolean onlyVisible)Returns the total number of columns in this model.Enumeration<TableColumn>getColumns(boolean onlyVisible)Returns anEnumerationof all the columns in the model.booleanisColumnVisible(TableColumn aColumn)Checks whether the specified column is currently visible.voidmoveColumn(int oldIndex, int newIndex)Moves the column fromoldIndextonewIndex.voidremoveColumn(TableColumn column)Removescolumnfrom this column model.voidsetColumnVisible(TableColumn column, boolean visible)Sets the visibility of the specified TableColumn.voidtableChanged(TableModelEvent e)-
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 Vector<TableColumn> allTableColumns
Array of TableColumn objects in this model. Holds all column objects, regardless of their visibility.
-
-
Constructor Detail
-
HidableTableColumnModel
public HidableTableColumnModel(TableModel model)
-
-
Method Detail
-
setColumnVisible
public void setColumnVisible(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/hidevisible- its new visibility status
-
isColumnVisible
public boolean isColumnVisible(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?])
-
addColumn
public void addColumn(TableColumn column)
Appendcolumnto the right of exisiting columns. PostscolumnAddedevent.- Specified by:
addColumnin interfaceTableColumnModel- Overrides:
addColumnin classDefaultTableColumnModel- Parameters:
column- The column to be added- Throws:
IllegalArgumentException- ifcolumnisnull- See Also:
removeColumn(javax.swing.table.TableColumn)
-
removeColumn
public void removeColumn(TableColumn column)
Removescolumnfrom this column model. PostscolumnRemovedevent. Will do nothing if the column is not in this model.- Specified by:
removeColumnin interfaceTableColumnModel- Overrides:
removeColumnin classDefaultTableColumnModel- Parameters:
column- the column to be added- See Also:
addColumn(javax.swing.table.TableColumn)
-
moveColumn
public void moveColumn(int oldIndex, int newIndex)Moves the column fromoldIndextonewIndex. PostscolumnMovedevent. Will not move any columns ifoldIndexequalsnewIndex.- Specified by:
moveColumnin interfaceTableColumnModel- Overrides:
moveColumnin classDefaultTableColumnModel- Parameters:
oldIndex- index of column to be movednewIndex- new index of the column- Throws:
IllegalArgumentException- if eitheroldIndexornewIndexare not in [0, getColumnCount() - 1]
-
getColumnCount
public 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)
-
getColumns
public Enumeration<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
-
getColumn
public TableColumn getColumn(int columnIndex, boolean onlyVisible)
Returns theTableColumnobject for the column atcolumnIndex.- Parameters:
columnIndex- the index of the column desiredonlyVisible- 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
-
tableChanged
public void tableChanged(TableModelEvent e)
- Specified by:
tableChangedin interfaceTableModelListener
-
createColumnsFromModel
public void createColumnsFromModel(TableModel newModel)
-
-