public class ColumnVisibilitySupport extends Object implements PropertyChangeListener
JTable. It has to be bound to a table instance upon creation.
This class notifies listeners about each showing/hiding of columns.
This class listens for changes of the column model of the table. Whenever the column model is replaced
by another instance all the invisible columns are forgotten. Unfortunately we are not able to notice
all changes. So the application may have to explicitly call clearInvisibleColumns().
See SortingTable.createDefaultColumnsFromModel() for a possible solution of this problem.
| Modifier and Type | Field and Description |
|---|---|
protected List<TableColumn> |
mInvisibleColumns
List of currently invisible table columns.
|
protected EventListenerList |
mListenerList
List of
ColumnVisibilityChangeListeners. |
protected JTable |
mTable
Table to operate on.
|
| Constructor and Description |
|---|
ColumnVisibilitySupport(JTable pTable)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addColumnVisibilityChangeListener(ColumnVisibilityChangeListener pListener)
Add a listener for showing/hiding of columns.
|
void |
clearInvisibleColumns()
Clear the list of invisible columns.
|
protected void |
fireColumnVisibilityEventHidden(TableColumn pColumn)
Notify our listeners that a table column was hidden.
|
protected void |
fireColumnVisibilityEventShown(TableColumn pColumn)
Notify our listeners that a table column was shown.
|
boolean[] |
getColumnsVisible()
Get the visibility of all table columns at once.
|
TableColumn |
getInvisibleColumn(int pModelIndex)
Fetch the hidden table column for a model index.
|
JTable |
getTable()
Access the table we work on.
|
protected void |
hideColumn(int pModelIndex)
Hide a column of our table.
|
boolean |
isAllColumnsVisible()
Test if all columns are visible.
|
boolean |
isColumnVisible(int pModelIndex)
Test whether a table column is currently visible.
|
void |
propertyChange(PropertyChangeEvent pEvent)
Forget all invisible columns if the column model of the table is changed.
|
void |
removeColumnVisibilityChangeListener(ColumnVisibilityChangeListener pListener)
Remove a listener for showing/hiding of columns.
|
void |
setAllColumnsVisible()
Make all table columns visible.
|
void |
setColumnsVisible(boolean[] pVisible)
Set the visibility of all table columns at once.
|
void |
setColumnVisible(int pModelIndex,
boolean pVisible)
Show or hide a table column.
|
protected void |
showColumn(int pModelIndex)
Show a column of this table.
|
protected JTable mTable
protected List<TableColumn> mInvisibleColumns
TableColumn objects are stored in this list.protected EventListenerList mListenerList
ColumnVisibilityChangeListeners.public ColumnVisibilitySupport(JTable pTable)
pTable - table to operate on (must not be null)public JTable getTable()
protected void hideColumn(int pModelIndex)
pModelIndex - column index in the table modelprotected void showColumn(int pModelIndex)
pModelIndex - column index in the table modelpublic boolean isColumnVisible(int pModelIndex)
pModelIndex - column index in the table modeltrue if table column is visiblepublic void setColumnVisible(int pModelIndex,
boolean pVisible)
pModelIndex - column index in the table modelpVisible - true to make the column visiblepublic boolean[] getColumnsVisible()
boolean[]. There is an
entry in this array for each table model column. true
means the respective column is visible. false makes the
column hidden.public void setColumnsVisible(boolean[] pVisible)
boolean[]. There must be an
entry in this array for each table model column. true
means the respective column is visible. false makes the
column hidden.pVisible - visiblity information for each column in the table modelIllegalArgumentException - if visible is null or has a different number of entries than the table modelpublic void setAllColumnsVisible()
public boolean isAllColumnsVisible()
true if there are currently no invisible columnspublic TableColumn getInvisibleColumn(int pModelIndex)
null.pModelIndex - the model indexnullpublic void clearInvisibleColumns()
This method must be called whenever the table column model is changed completely.
We do our best to catch this in propertyChange(java.beans.PropertyChangeEvent). But we cannot notice all
changes. So you have to call this e.g. whenever JTable.createDefaultColumnsFromModel()
is called explicitely.
public void propertyChange(PropertyChangeEvent pEvent)
JTable.setColumnModel(TableColumnModel) or
implicitly by any action that calls JTable.createDefaultColumnsFromModel().propertyChange in interface PropertyChangeListenerpEvent - information about the changed propertypublic void addColumnVisibilityChangeListener(ColumnVisibilityChangeListener pListener)
pListener - listener to addpublic void removeColumnVisibilityChangeListener(ColumnVisibilityChangeListener pListener)
pListener - listener to removeprotected void fireColumnVisibilityEventShown(TableColumn pColumn)
pColumn - column that was shownprotected void fireColumnVisibilityEventHidden(TableColumn pColumn)
pColumn - column that was hiddenCopyright © 2017 Jürgen Zeller (privat). All rights reserved.