public class HidableTableColumnModel
extends javax.swing.table.DefaultTableColumnModel
implements javax.swing.event.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.DefaultTableColumnModel
,
original documentation,
Serialized FormModifier and Type | Field and Description |
---|---|
protected java.util.Vector<javax.swing.table.TableColumn> |
allTableColumns
Array of TableColumn objects in this model.
|
Constructor and Description |
---|
HidableTableColumnModel(javax.swing.table.TableModel model) |
Modifier and Type | Method and Description |
---|---|
void |
addColumn(javax.swing.table.TableColumn column)
Append
column to the right of exisiting columns. |
void |
createColumnsFromModel(javax.swing.table.TableModel newModel) |
javax.swing.table.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.
|
java.util.Enumeration<javax.swing.table.TableColumn> |
getColumns(boolean onlyVisible)
Returns an
Enumeration of all the columns in the model. |
boolean |
isColumnVisible(javax.swing.table.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(javax.swing.table.TableColumn column)
Removes
column from this column model. |
void |
setColumnVisible(javax.swing.table.TableColumn column,
boolean visible)
Sets the visibility of the specified TableColumn.
|
void |
tableChanged(javax.swing.event.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, valueChanged
protected java.util.Vector<javax.swing.table.TableColumn> allTableColumns
public HidableTableColumnModel(javax.swing.table.TableModel model)
public void setColumnVisible(javax.swing.table.TableColumn column, boolean visible)
column
- the column to show/hidevisible
- its new visibility statuspublic boolean isColumnVisible(javax.swing.table.TableColumn aColumn)
aColumn
- column to checkpublic void addColumn(javax.swing.table.TableColumn column)
column
to the right of exisiting columns.
Posts columnAdded
event.addColumn
in interface javax.swing.table.TableColumnModel
addColumn
in class javax.swing.table.DefaultTableColumnModel
column
- The column to be addedjava.lang.IllegalArgumentException
- if column
is null
removeColumn(javax.swing.table.TableColumn)
public void removeColumn(javax.swing.table.TableColumn column)
column
from this column model.
Posts columnRemoved
event.
Will do nothing if the column is not in this model.removeColumn
in interface javax.swing.table.TableColumnModel
removeColumn
in class javax.swing.table.DefaultTableColumnModel
column
- 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 javax.swing.table.TableColumnModel
moveColumn
in class javax.swing.table.DefaultTableColumnModel
oldIndex
- index of column to be movednewIndex
- new index of the columnjava.lang.IllegalArgumentException
- 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 java.util.Enumeration<javax.swing.table.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 javax.swing.table.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 columnIndex
public void tableChanged(javax.swing.event.TableModelEvent e)
tableChanged
in interface javax.swing.event.TableModelListener
public void createColumnsFromModel(javax.swing.table.TableModel newModel)