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
HidableTableColumnModel
extends 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 incolumnRemoved
event and showing it again will notify listeners of acolumnAdded
, and possibly acolumnMoved
event. 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 parameteronlyVisible
which let's you specify whether you want invisible columns taken into account.
-
-
Field Summary
Fields Modifier and Type Field Description protected Vector<TableColumn>
allTableColumns
Array 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 void
addColumn(TableColumn column)
Appendcolumn
to the right of exisiting columns.void
createColumnsFromModel(TableModel newModel)
TableColumn
getColumn(int columnIndex, boolean onlyVisible)
Returns theTableColumn
object for the column atcolumnIndex
.int
getColumnCount(boolean onlyVisible)
Returns the total number of columns in this model.Enumeration<TableColumn>
getColumns(boolean onlyVisible)
Returns anEnumeration
of all the columns in the model.boolean
isColumnVisible(TableColumn aColumn)
Checks whether the specified column is currently visible.void
moveColumn(int oldIndex, int newIndex)
Moves the column fromoldIndex
tonewIndex
.void
removeColumn(TableColumn column)
Removescolumn
from this column model.void
setColumnVisible(TableColumn column, boolean visible)
Sets the visibility of the specified TableColumn.void
tableChanged(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)
Appendcolumn
to the right of exisiting columns. PostscolumnAdded
event.- Specified by:
addColumn
in interfaceTableColumnModel
- Overrides:
addColumn
in classDefaultTableColumnModel
- Parameters:
column
- The column to be added- Throws:
IllegalArgumentException
- ifcolumn
isnull
- See Also:
removeColumn(javax.swing.table.TableColumn)
-
removeColumn
public void removeColumn(TableColumn column)
Removescolumn
from this column model. PostscolumnRemoved
event. Will do nothing if the column is not in this model.- Specified by:
removeColumn
in interfaceTableColumnModel
- Overrides:
removeColumn
in 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 fromoldIndex
tonewIndex
. PostscolumnMoved
event. Will not move any columns ifoldIndex
equalsnewIndex
.- Specified by:
moveColumn
in interfaceTableColumnModel
- Overrides:
moveColumn
in classDefaultTableColumnModel
- Parameters:
oldIndex
- index of column to be movednewIndex
- new index of the column- Throws:
IllegalArgumentException
- if eitheroldIndex
ornewIndex
are 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
tableColumns
array - See Also:
getColumns(boolean)
-
getColumns
public Enumeration<TableColumn> getColumns(boolean onlyVisible)
Returns anEnumeration
of all the columns in the model.- Parameters:
onlyVisible
- if set all invisible columns will be missing from the enumeration.- Returns:
- an
Enumeration
of the columns in the model
-
getColumn
public TableColumn getColumn(int columnIndex, boolean onlyVisible)
Returns theTableColumn
object 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
TableColumn
object for the column atcolumnIndex
-
tableChanged
public void tableChanged(TableModelEvent e)
- Specified by:
tableChanged
in interfaceTableModelListener
-
createColumnsFromModel
public void createColumnsFromModel(TableModel newModel)
-
-