|
swingx Version 2009-07-31 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface TableColumnModelExt
An extension of TableColumnModel
suitable for use with
JXTable
. It extends the notion of columns considered as part
of the view realm to include invisible columns. Conceptually, there are
several sets of "columns":
TableModel
. They are but
a virtual concept, characterizable f.i. by (model) column index, (model)
column name.
TableColumnExt
objects added to the
TableColumnModelExt
, each typically created and configured in
relation to a model column. These can be regarded as a kind of subset of the
model columns (not literally, obviously). Each view column belongs to exactly
one of the following (real) subsets:
ColumnControlButton
.
An example to programmatically hide the first visible column in the column model:
TableColumnExt columnExt = columnModel.getColumnExt(0);
if (columnExt != null) {
columnExt.setVisible(false);
}
Note that it is principally allowed to add standard TableColumn
s.
Practically, it doesn't make much sense to do so - they will always be
visible.
While individual visible columns can be requested by both column identifier
and column index, the latter is not available for hidden columns. An example
to programmatically guarantee that the view column which corresponds to the
first column in the associated TableModel
.
List<TableColumn> columns = colModel.getColumns(true);
for (TableColumn column : columns) {
if (column.getModelIndex() == 0) {
if (column instanceof TableColumnExt) {
((TableColumnExt) column).setVisible(false);
}
return;
}
}
Alternatively, the column could be requested directly by identifier. By
default the column's headerValue is returned as identifier, if none is set.
Object identifier = tableModel.getColumnName(0);
TableColumnExt columnExt = columnModel.getColumnExt(identifier);
if (columnExt != null) {
columnExt.setVisible(false);
}
Relying on default identifiers is inherently brittle (headerValue
s might
change f.i. with Locale
s), so explicit configuration of columns with
identifiers is strongly recommended. A custom ColumnFactory
helps to automate column configuration.
This class guarantees to notify registered
TableColumnModelListener
s of type
TableColumnModelExtListener
about propertyChanges fired by
contained TableColumn
s.
An example of a client which adjusts itself based on
headerValue
property of visible columns:
TableColumnModelExtListener l = new TableColumnModelExtListener() {
public void columnPropertyChange(PropertyChangeEvent event) {
if ("headerValue".equals(event.getPropertyName())) {
TableColumn column = (TableColumn) event.getSource();
if ((column instanceof TableColumnExt)
&& !((TableColumnExt) column).isVisible()) {
return;
}
resizeAndRepaint();
}
}
public void columnAdded(TableColumnModelEvent e) {
}
public void columnMarginChanged(ChangeEvent e) {
}
public void columnMoved(TableColumnModelEvent e) {
}
public void columnRemoved(TableColumnModelEvent e) {
}
public void columnSelectionChanged(ListSelectionEvent e) {
}
};
columnModel.addColumnModelListener(l);
DefaultTableColumnModelExt
,
TableColumnExt
,
TableColumnModelExtListener
,
ColumnControlButton
,
JXTable.setColumnControlVisible(boolean)
,
ColumnFactory
Method Summary | |
---|---|
void |
addColumnModelListener(TableColumnModelListener x)
Adds a listener for table column model events. |
int |
getColumnCount(boolean includeHidden)
Returns the number of contained columns. |
TableColumnExt |
getColumnExt(int columnIndex)
Returns the TableColumnExt at view position
columnIndex . |
TableColumnExt |
getColumnExt(Object identifier)
Returns the first TableColumnExt with the given
identifier . |
List<TableColumn> |
getColumns(boolean includeHidden)
Returns a List of contained TableColumn s. |
Methods inherited from interface javax.swing.table.TableColumnModel |
---|
addColumn, getColumn, getColumnCount, getColumnIndex, getColumnIndexAtX, getColumnMargin, getColumns, getColumnSelectionAllowed, getSelectedColumnCount, getSelectedColumns, getSelectionModel, getTotalColumnWidth, moveColumn, removeColumn, removeColumnModelListener, setColumnMargin, setColumnSelectionAllowed, setSelectionModel |
Method Detail |
---|
int getColumnCount(boolean includeHidden)
includeHidden
is true or
false, respectively. If false, this method returns the same count as
getColumnCount()
.
includeHidden
- a boolean to indicate whether invisible columns
should be included
List<TableColumn> getColumns(boolean includeHidden)
List
of contained TableColumn
s.
Includes or excludes invisible columns, depending on whether the
includeHidden
is true or false, respectively. If false, an
Iterator
over the List is equivalent to the
Enumeration
returned by getColumns()
.
NOTE: the order of columns in the List depends on whether or not the invisible columns are included, in the former case it's the insertion order in the latter it's the current order of the visible columns.
includeHidden
- a boolean to indicate whether invisible columns
should be included
List
of contained columns.TableColumnExt getColumnExt(Object identifier)
TableColumnExt
with the given
identifier
. The return value is null if there is no contained
column with identifier or if the column with identifier
is not
of type TableColumnExt
. The returned column
may be visible or hidden.
identifier
- the object used as column identifier
TableColumnExt
with the given identifier or
null if none is foundTableColumnExt getColumnExt(int columnIndex)
TableColumnExt
at view position
columnIndex
. The return value is null, if the
column at position columnIndex
is not of type
TableColumnExt
.
The returned column is visible.
columnIndex
- the index of the column desired
TableColumnExt
object that matches the column
index
ArrayIndexOutOfBoundsException
- if columnIndex out of allowed
range, that is if
(columnIndex < 0) || (columnIndex >= getColumnCount())
.void addColumnModelListener(TableColumnModelListener x)
addColumnModelListener
in interface TableColumnModel
x
- a TableColumnModelListener
object
|
swingx Version 2009-07-31 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |