org.jdesktop.swingx
Class JXTable

java.lang.Object
extended by java.awt.Component
extended by java.awt.Container
extended by javax.swing.JComponent
extended by javax.swing.JTable
extended by org.jdesktop.swingx.JXTable
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, EventListener, Accessible, CellEditorListener, ListSelectionListener, TableColumnModelListener, TableModelListener, Scrollable
Direct Known Subclasses:
JXTreeTable

public class JXTable
extends JTable

This is a partial copy of JXTable javadoc. The focus is on fields/methods (their details section) related to the table's enhanced column support, all summaries and unrelated field/method details have been cut.

Note: links inside this document are working, while links to other documents might not.

Field Detail

None

Constructor Detail

None

Method Detail

[...]



isColumnControlVisible

public boolean isColumnControlVisible()
Returns the column control visible property.

Returns:
boolean to indicate whether the column control is visible.
See Also:
setColumnControlVisible(boolean), setColumnControl(JComponent)

setColumnControlVisible

public void setColumnControlVisible(boolean visible)
Sets the column control visible property. If true and JXTable is contained in a JScrollPane, the table adds the column control to the trailing corner of the scroll pane.

Note: if the table is not inside a JScrollPane the column control is not shown even if this returns true. In this case it's the responsibility of the client code to actually show it.

The default value is false.

Parameters:
visible - boolean to indicate if the column control should be shown
See Also:
#getColumnControlVisible(), setColumnControl(JComponent)

getColumnControl

public JComponent getColumnControl()
Returns the component used as column control. Lazily creates the control to the default if it is null.

Returns:
component for column control, guaranteed to be != null.
See Also:
setColumnControl(JComponent), createDefaultColumnControl()

setColumnControl

public void setColumnControl(JComponent columnControl)
Sets the component used as column control. Updates the enclosing JScrollPane if appropriate. Passing a null parameter restores the column control to the default.

The component is automatically visible only if the columnControlVisible property is true and the table is contained in a JScrollPane.

NOTE: from the table's perspective, the column control is simply a JComponent to add to and keep in the trailing corner of the scrollpane. (if any). It's up the concrete control to configure itself from and keep synchronized to the columns' states.

Parameters:
columnControl - the JComponent to use as columnControl.
See Also:
getColumnControl(), createDefaultColumnControl(), setColumnControlVisible(boolean)

createDefaultColumnControl

protected JComponent createDefaultColumnControl()
Creates the default column control used by this table. This implementation returns a ColumnControlButton configured with default ColumnControlIcon.

Returns:
the default component used as column control.
See Also:
setColumnControl(JComponent), ColumnControlButton, ColumnControlIcon

setComponentOrientation

public void setComponentOrientation(ComponentOrientation o)
Sets the language-sensitive orientation that is to be used to order the elements or text within this component.

Overridden to work around a core bug: JScrollPane can't cope with corners when changing component orientation at runtime. This method explicitly re-configures the column control.

Overrides:
setComponentOrientation in class Component
Parameters:
o - the ComponentOrientation for this table.
See Also:
Component.setComponentOrientation(ComponentOrientation)

configureEnclosingScrollPane

protected void configureEnclosingScrollPane()
Configures the enclosing JScrollPane.

Overridden to addionally configure the upper trailing corner with the column control.

Overrides:
configureEnclosingScrollPane in class JTable
See Also:
configureColumnControl()

configureColumnControl

protected void configureColumnControl()
Configures the upper trailing corner of an enclosing JScrollPane. Adds/removes the ColumnControl depending on the columnControlVisible property.

See Also:
setColumnControlVisible(boolean), setColumnControl(JComponent)


[...]


setValueAt

public void setValueAt(Object aValue,
int row,
int column)
Overridden to account for row index mapping. This implementation respects the cell's editability, that is it has no effect if !isCellEditable(row, column). Sets the value for the cell in the table model at row and column.

Note: The column is specified in the table view's display order, and not in the TableModel's column order. This is an important distinction because as the user rearranges the columns in the table, the column at a given index in the view will change. Meanwhile the user's actions never affect the model's column ordering. aValue is the new value.

Overrides:
setValueAt in class JTable
Parameters:
aValue - the new value
row - the row of the cell to be changed
column - the column of the cell to be changed
See Also:
isCellEditable(int, int)

isCellEditable

public boolean isCellEditable(int row,
int column)
Returns true if the cell at row and column is editable. Otherwise, invoking setValueAt on the cell will have no effect.

Overridden to account for row index mapping and to support a layered editability control:

The view cell is considered editable only if all three layers are enabled.

Overrides:
isCellEditable in class JTable
Parameters:
row - the row index in view coordinates
column - the column index in view coordinates
Returns:
true if the cell is editable
See Also:
setValueAt(Object, int, int), isEditable(), TableColumnExt.isEditable(), TableModel.isCellEditable(int, int)



[...]



getColumn

public TableColumn getColumn(int viewColumnIndex)
Returns the TableColumn at view position columnIndex. The return value is not null.

NOTE: This delegate method is added to protect developer's from unexpected exceptions in jdk1.5+. Super does not expose the TableColumn access by index which may lead to unexpected IllegalArgumentException: If client code assumes the delegate method is available, autoboxing will convert the given int to an Integer which will call the getColumn(Object) method.

Parameters:
viewColumnIndex - index of the column with the object in question
Returns:
the TableColumn object that matches the column index
Throws:
ArrayIndexOutOfBoundsException - if viewColumnIndex out of allowed range.
See Also:
JTable.getColumn(Object), getColumnExt(int), TableColumnModel.getColumn(int)

getColumns

public List<TableColumn> getColumns()
Returns a List of visible TableColumns.

Returns:
a List of visible columns.
See Also:
getColumns(boolean)

getColumnMargin

public int getColumnMargin()
Returns the margin between columns.

Convenience to expose column model properties through JXTable api.

Returns:
the margin between columns
See Also:
setColumnMargin(int), TableColumnModel.getColumnMargin()

setColumnMargin

public void setColumnMargin(int value)
Sets the margin between columns. Convenience to expose column model properties through JXTable api.

Parameters:
value - margin between columns; must be greater than or equal to zero.
See Also:
getColumnMargin(), TableColumnModel#setColumnMargin()

getColumnCount

public int getColumnCount(boolean includeHidden)
Returns the number of contained columns. The count includes or excludes invisible columns, depending on whether the includeHidden is true or false, respectively. If false, this method returns the same count as getColumnCount(). If the columnModel is not of type TableColumnModelExt, the parameter value has no effect.

Parameters:
includeHidden - a boolean to indicate whether invisible columns should be included
Returns:
the number of contained columns, including or excluding the invisible as specified.
See Also:
JTable.getColumnCount(), TableColumnModelExt.getColumnCount(boolean)

getColumns

public List<TableColumn> getColumns(boolean includeHidden)
Returns a List of contained TableColumns. 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(). If the columnModel is not of type TableColumnModelExt, the parameter value has no effect.

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.

Parameters:
includeHidden - a boolean to indicate whether invisible columns should be included
Returns:
a List of contained columns.
See Also:
getColumns(), TableColumnModelExt.getColumns(boolean)

getColumnExt

public TableColumnExt getColumnExt(Object identifier)
Returns the first 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.

Parameters:
identifier - the object used as column identifier
Returns:
first TableColumnExt with the given identifier or null if none is found
See Also:
getColumnExt(int), JTable.getColumn(Object), TableColumnModelExt.getColumnExt(Object)

getColumnExt

public TableColumnExt getColumnExt(int viewColumnIndex)
Returns the 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.

Parameters:
viewColumnIndex - the index of the column desired
Returns:
the TableColumnExt object that matches the column index
Throws:
ArrayIndexOutOfBoundsException - if columnIndex out of allowed range, that is if (columnIndex < 0) || (columnIndex >= getColumnCount()).
See Also:
getColumnExt(Object), getColumn(int), TableColumnModelExt.getColumnExt(int)

setColumnSequence

public void setColumnSequence(Object[] identifiers)
Reorders the columns in the sequence given array. Logical names that do not correspond to any column in the model will be ignored. Columns with logical names not contained are added at the end. PENDING JW - do we want this? It's used by JNTable.

Parameters:
identifiers - array of logical column names
See Also:
getColumns(boolean)

createDefaultColumnsFromModel

public void createDefaultColumnsFromModel()
Creates, configures and adds default TableColumns for columns in this table's TableModel. Removes all currently contained TableColumns. The exact type and configuration of the columns is controlled by the ColumnFactory.

Overrides:
createDefaultColumnsFromModel in class JTable
See Also:
ColumnFactory

getColumnFactory

public ColumnFactory getColumnFactory()
Returns the ColumnFactory.

Returns:
the columnFactory to use for column creation and configuration.
See Also:
setColumnFactory(ColumnFactory), ColumnFactory

setColumnFactory

public void setColumnFactory(ColumnFactory columnFactory)
Sets the ColumnFactory to use for column creation and configuration. The default value is the shared application ColumnFactory.

Parameters:
columnFactory - the factory to use, null indicates to use the shared application factory.
See Also:
getColumnFactory(), ColumnFactory

packTable

public void packTable(int margin)
Packs all the columns to their optimal size. Works best with auto resizing turned off.

Parameters:
margin - the margin to apply to each column.
See Also:
packColumn(int, int), packColumn(int, int, int)

packColumn

public void packColumn(int column,
int margin)
Packs an indivudal column in the table.

Parameters:
column - The Column index to pack in View Coordinates
margin - The Margin to apply to the column width.
See Also:
packColumn(int, int, int), packTable(int)

packColumn

public void packColumn(int column,
int margin,
int max)
Packs an indivual column in the table to less than or equal to the maximum witdth. If maximum is -1 then the column is made as wide as it needs.

Parameters:
column - the column index to pack in view coordinates
margin - the margin to apply to the column
max - the maximum width the column can be resized to, -1 means no limit
See Also:
packColumn(int, int), packTable(int), ColumnFactory.packColumn(JXTable, TableColumnExt, int, int)

[...]


initializeColumnPreferredWidth

protected void initializeColumnPreferredWidth(TableColumn column)
Initialize the preferredWidth of the specified column based on the column's prototypeValue property. If the column is not an instance of TableColumnExt or prototypeValue is null then the preferredWidth is left unmodified.

TODO JW - need to cleanup getScrollablePreferred (refactor and inline) update doc - what exactly happens is left to the columnfactory.

Parameters:
column - TableColumn object representing view column
See Also:
TableColumnExt.setPrototypeValue(java.lang.Object)

[...]



isEditable

public boolean isEditable()
Returns the editable property of the JXTable as a whole.

Returns:
boolean to indicate if the table is editable.
See Also:
setEditable(boolean)

setEditable

public void setEditable(boolean editable)
Sets the editable property. This property allows to mark all cells in a table as read-only, independent of their per-column editability as returned by TableColumnExt.isEditable() and their per-cell editability as returned by the TableModel.isCellEditable. If a cell is read-only in its column or model layer, this property has no effect.

The default value is true.

Parameters:
editable - the flag to indicate if the table is editable.
See Also:
isEditable(), isCellEditable(int, int)

[...]




createDefaultColumnModel

protected TableColumnModel createDefaultColumnModel()
Returns the default column model object, which is a DefaultTableColumnModel. A subclass can override this method to return a different column model object.

Overridden to return a DefaultTableColumnModelExt.

Overrides:
createDefaultColumnModel in class JTable
Returns:
the default column model object
See Also:
DefaultTableColumnModelExt