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 to TableColumnModelListener.
Therefore hiding a column will result in columnRemoved event and showing it
again will notify listeners of a columnAdded, and possibly a columnMoved 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 parameter onlyVisible which let's
you specify whether you want invisible columns taken into account.| Modifier and Type | Field and Description |
|---|---|
protected Vector<TableColumn> |
allTableColumns
Array of TableColumn objects in this model.
|
changeEvent, columnMargin, columnSelectionAllowed, listenerList, selectionModel, tableColumns, totalColumnWidth| Constructor and Description |
|---|
HidableTableColumnModel(TableModel model) |
| Modifier and Type | Method and Description |
|---|---|
void |
addColumn(TableColumn column)
Append
column to the right of exisiting columns. |
void |
createColumnsFromModel(TableModel newModel) |
TableColumn |
getColumn(int columnIndex,
boolean onlyVisible)
Returns the
TableColumn object for the column
at columnIndex. |
int |
getColumnCount(boolean onlyVisible)
Returns the total number of columns in this model.
|
Enumeration<TableColumn> |
getColumns(boolean onlyVisible)
Returns an
Enumeration 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 from
oldIndex to newIndex. |
void |
removeColumn(TableColumn column)
Removes
column from this column model. |
void |
setColumnVisible(TableColumn column,
boolean visible)
Sets the visibility of the specified TableColumn.
|
void |
tableChanged(TableModelEvent e) |
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, valueChangedprotected Vector<TableColumn> allTableColumns
public HidableTableColumnModel(TableModel model)
public void setColumnVisible(TableColumn column, boolean visible)
column - the column to show/hidevisible - its new visibility statuspublic boolean isColumnVisible(TableColumn aColumn)
aColumn - column to checkpublic void addColumn(TableColumn column)
column to the right of exisiting columns.
Posts columnAdded event.addColumn in interface TableColumnModeladdColumn in class DefaultTableColumnModelcolumn - The column to be addedIllegalArgumentException - if column is nullremoveColumn(javax.swing.table.TableColumn)public void removeColumn(TableColumn column)
column from this column model.
Posts columnRemoved event.
Will do nothing if the column is not in this model.removeColumn in interface TableColumnModelremoveColumn in class DefaultTableColumnModelcolumn - the column to be addedaddColumn(javax.swing.table.TableColumn)public void moveColumn(int oldIndex,
int newIndex)
oldIndex to newIndex.
Posts columnMoved event.
Will not move any columns if oldIndex equals newIndex.moveColumn in interface TableColumnModelmoveColumn in class DefaultTableColumnModeloldIndex - index of column to be movednewIndex - new index of the columnIllegalArgumentException - if either oldIndex or
newIndex
are not in [0, getColumnCount() - 1]public int getColumnCount(boolean onlyVisible)
onlyVisible - if set only visible columns will be countedtableColumns arraygetColumns(boolean)public Enumeration<TableColumn> getColumns(boolean onlyVisible)
Enumeration of all the columns in the model.onlyVisible - if set all invisible columns will be missing from the enumeration.Enumeration of the columns in the modelpublic TableColumn getColumn(int columnIndex, boolean onlyVisible)
TableColumn object for the column
at columnIndex.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 columnsTableColumn object for the column
at columnIndexpublic void tableChanged(TableModelEvent e)
tableChanged in interface TableModelListenerpublic void createColumnsFromModel(TableModel newModel)