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 ..., 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

HORIZONTALSCROLL_ACTION_COMMAND

public static final String HORIZONTALSCROLL_ACTION_COMMAND
Constant string for horizontal scroll actions, used in JXTable's Action Map.

See Also:
Constant Field Values

PACKALL_ACTION_COMMAND

public static final String PACKALL_ACTION_COMMAND
Constant string for packing all columns, used in JXTable's Action Map.

See Also:
Constant Field Values

PACKSELECTED_ACTION_COMMAND

public static final String PACKSELECTED_ACTION_COMMAND
Constant string for packing selected columns, used in JXTable's Action Map.

See Also:
Constant Field Values

UIPREFIX

public static final String UIPREFIX
The prefix marker to find component related properties in the resourcebundle.

See Also:
Constant Field Values

MATCH_HIGHLIGHTER

public static final String MATCH_HIGHLIGHTER
key for client property to use SearchHighlighter as match marker.

See Also:
Constant Field Values

filters

protected FilterPipeline filters
The FilterPipeline for the table.


highlighters

protected HighlighterPipeline highlighters
The HighlighterPipeline for the table.


resetDefaultTableCellRendererHighlighter

protected Highlighter resetDefaultTableCellRendererHighlighter
The Highlighter used to hack around DefaultTableCellRenderer's color memory.


dataAdapter

protected ComponentAdapter dataAdapter
The ComponentAdapter for model data access.


isXTableRowHeightSet

protected boolean isXTableRowHeightSet
Flag to distinguish internal settings of rowheight from client code settings. The rowHeight will be internally adjusted to font size on instantiation and in updateUI if the height has not been set explicitly by the application.

See Also:
adminSetRowHeight(int)

searchable

protected Searchable searchable
property to control search behaviour.

Constructor Detail

JXTable

public JXTable()
Instantiates a JXTable with a default table model, no data.


JXTable

public JXTable(TableModel dm)
Instantiates a JXTable with a specific table model.

Parameters:
dm - The model to use.

JXTable

public JXTable(TableModel dm,
TableColumnModel cm)
Instantiates a JXTable with a specific table model.

Parameters:
dm - The model to use.

JXTable

public JXTable(TableModel dm,
TableColumnModel cm,
ListSelectionModel sm)
Instantiates a JXTable with a specific table model, column model, and selection model.

Parameters:
dm - The table model to use.
cm - The colomn model to use.
sm - The list selection model to use.

JXTable

public JXTable(int numRows,
int numColumns)
Instantiates a JXTable for a given number of columns and rows.

Parameters:
numRows - Count of rows to accomodate.
numColumns - Count of columns to accomodate.

JXTable

public JXTable(Vector rowData,
Vector columnNames)
Instantiates a JXTable with data in a vector or rows and column names.

Parameters:
rowData - Row data, as a Vector of Objects.
columnNames - Column names, as a Vector of Strings.

JXTable

public JXTable(Object[][] rowData,
Object[] columnNames)
Instantiates a JXTable with data in a array or rows and column names.

Parameters:
rowData - Row data, as a two-dimensional Array of Objects (by row, for column).
columnNames - Column names, as a Array of Strings.
Method Detail

init

protected void init()
Initializes the table for use.


setRolloverEnabled

public void setRolloverEnabled(boolean rolloverEnabled)
Property to enable/disable rollover support. This can be enabled to show "live" rollover behaviour, f.i. the cursor over LinkModel cells. Default is enabled. If rollover effects are not used, this property should be disabled.

Parameters:
rolloverEnabled -

getLinkController

protected JXTable.TableRolloverController getLinkController()

createLinkController

protected JXTable.TableRolloverController createLinkController()

createRolloverProducer

protected RolloverProducer createRolloverProducer()
creates and returns the RolloverProducer to use.

Returns:
RolloverProducer

isRolloverEnabled

public boolean isRolloverEnabled()
Returns the rolloverEnabled property.

Returns:
true if rollover is enabled

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)

packAll

public void packAll()
This resizes all columns to fit the viewport; if horizontal scrolling is enabled, all columns will get their preferred width. This can be triggered by the "packAll" BoundAction on the table as well.


packSelected

public void packSelected()
This resizes selected columns to fit the viewport; if horizontal scrolling is enabled, selected columns will get their preferred width. This can be triggered by the "packSelected" BoundAction on the table as well.


columnSelectionChanged

public void columnSelectionChanged(ListSelectionEvent e)
Notifies the table that a new column has been selected. overridden to update the enabled state of the packSelected action.

Specified by:
columnSelectionChanged in interface TableColumnModelListener
Overrides:
columnSelectionChanged in class JTable
Parameters:
e - the event received
See Also:
TableColumnModelListener

setHorizontalScrollEnabled

public void setHorizontalScrollEnabled(boolean enabled)
Controls horizontal scrolling in the viewport, and works in coordination with column sizing. It enables a enhanced AutoResizeMode which always fills the Viewport horizontally and shows the horizontal scrollbar if necessary.

PENDING: add a "real" mode? Problematic because there are several places in core which check for #AUTO_RESIZE_OFF, can't use different value without unwanted side-effects. The current solution with tagging the #AUTO_RESIZE_OFF by a boolean flag #intelliMode is brittle - need to be very careful to turn off again ... Another problem is to keep the horizontalScrollEnabled toggling action in synch with this property. Yet another problem is the change notification: currently this is _not_ a bound property.

Parameters:
enabled - a boolean indicating whether enhanced auto resize off is enabled.

isHorizontalScrollEnabled

protected boolean isHorizontalScrollEnabled()
Returns the current setting for horizontal scrolling.


setAutoResizeMode

public void setAutoResizeMode(int mode)
overridden to update the show horizontal scrollbar action's selected state. PENDING: to enable/disable the enhanced auto-resize-off use exclusively #setHorizontalScrollEnabled(). This method can't cope with it. Sets the table's auto resize mode when the table is resized.

Overrides:
setAutoResizeMode in class JTable
Parameters:
mode - One of 5 legal values: AUTO_RESIZE_OFF, AUTO_RESIZE_NEXT_COLUMN, AUTO_RESIZE_SUBSEQUENT_COLUMNS, AUTO_RESIZE_LAST_COLUMN, AUTO_RESIZE_ALL_COLUMNS
See Also:
JTable.getAutoResizeMode(), JTable.doLayout()

updateHorizontalAction

protected void updateHorizontalAction()
synch selected state of horizontal scroll en/disabling action with horizont scroll enabled property. "real" binding would help ...


getScrollableTracksViewportWidth

public boolean getScrollableTracksViewportWidth()
overridden to support auto-expand to parent's width if enabled and necessary.

Specified by:
getScrollableTracksViewportWidth in interface Scrollable
Overrides:
getScrollableTracksViewportWidth in class JTable
Returns:
false if autoResizeMode is set to AUTO_RESIZE_OFF, otherwise returns true
See Also:
Scrollable.getScrollableTracksViewportWidth()

doLayout

public void doLayout()
overridden to support auto-expand to parent's width if enabled and necessary.

Overrides:
doLayout in class JTable
See Also:
LayoutManager.layoutContainer(java.awt.Container), Container.setLayout(java.awt.LayoutManager), Container.validate()

columnMarginChanged

public void columnMarginChanged(ChangeEvent e)
Description copied from class: javax.swing.JTable
Invoked when a column is moved due to a margin change. If a cell is being edited, then editing is stopped and the cell is redrawn.

Application code will not use these methods explicitly, they are used internally by JTable.

Specified by:
columnMarginChanged in interface TableColumnModelListener
Overrides:
columnMarginChanged in class JTable
Parameters:
e - the event received
See Also:
TableColumnModelListener

setFillsViewportHeight

public void setFillsViewportHeight(boolean fillsViewportHeight)
Set flag to control JXTable's scrollableTracksViewportHeight property. If true the table's height will be always at least as large as the containing (viewport?) parent, if false the table's height will be independent of parent's height.


getFillsViewportHeight

public boolean getFillsViewportHeight()
Returns the flag to control JXTable scrollableTracksViewportHeight property. If true the table's height will be always at least as large as the containing (viewport?) parent, if false the table's height will be independent of parent's height.

Returns:
true if the table's height will always be at least as large as the containing parent, false if it is independent

getScrollableTracksViewportHeight

public boolean getScrollableTracksViewportHeight()
Overridden to control the tracksHeight property depending on fillsViewportHeight and relative size to containing parent (viewport?).

Specified by:
getScrollableTracksViewportHeight in interface Scrollable
Overrides:
getScrollableTracksViewportHeight in class JTable
Returns:
true if the control flag is true and the containing viewport height > prefHeight, else returns false.
See Also:
Scrollable.getScrollableTracksViewportHeight()

getRowCount

public int getRowCount()
Returns the row count in the table; if filters are applied, this is the filtered row count.

Overrides:
getRowCount in class JTable
Returns:
the number of rows in this table's model
See Also:
JTable.getColumnCount()

isHierarchical

public boolean isHierarchical(int column)

convertRowIndexToModel

public int convertRowIndexToModel(int row)
Convert row index from view coordinates to model coordinates accounting for the presence of sorters and filters.

Parameters:
row - row index in view coordinates
Returns:
row index in model coordinates

convertRowIndexToView

public int convertRowIndexToView(int row)
Convert row index from model coordinates to view coordinates accounting for the presence of sorters and filters.

Parameters:
row - row index in model coordinates
Returns:
row index in view coordinates

getValueAt

public Object getValueAt(int row,
int column)
Overridden to account for row index mapping. Returns the cell value 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.

Overrides:
getValueAt in class JTable
Parameters:
row - the row whose value is to be queried
column - the column whose value is to be queried
Returns:
the Object at the specified cell

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)

setSelectionModel

public void setSelectionModel(ListSelectionModel newModel)
Overridden to update selectionMapper

Overrides:
setSelectionModel in class JTable
Parameters:
newModel - the new selection model
See Also:
JTable.getSelectionModel()

setModel

public void setModel(TableModel newModel)
Sets the data model for this table to newModel and registers with it for listener notifications from the new data model.

Overrides:
setModel in class JTable
Parameters:
newModel - the new data source for this table
See Also:
JTable.getModel()

tableChanged

public void tableChanged(TableModelEvent e)
additionally updates filtered state. Invoked when this table's TableModel generates a TableModelEvent. The TableModelEvent should be constructed in the coordinate system of the model; the appropriate mapping to the view coordinate system is performed by this JTable when it receives the event.

Application code will not use these methods explicitly, they are used internally by JTable.

Note that as of 1.3, this method clears the selection, if any.

Specified by:
tableChanged in interface TableModelListener
Overrides:
tableChanged in class JTable

isDataChanged

protected boolean isDataChanged(TableModelEvent e)
Convenience method to detect dataChanged event.

Parameters:
e - the event to examine.
Returns:
true if the event is of type dataChanged, false else.

isUpdate

protected boolean isUpdate(TableModelEvent e)
Convenience method to detect update event.

Parameters:
e - the event to examine.
Returns:
true if the event is of type update and not dataChanged, false else.

isStructureChanged

protected boolean isStructureChanged(TableModelEvent e)
Convenience method to detect a structureChanged event type.

Parameters:
e - the event to examine.
Returns:
true if the event is of type structureChanged or null, false else.

updateViewSizeSequence

protected void updateViewSizeSequence()
Called if individual row height mapping need to be updated. This implementation guards against unnessary access of super's private rowModel field.


getSelectionMapper

public SelectionMapper getSelectionMapper()
Returns:
SelectionMapper

getFilters

public FilterPipeline getFilters()
Returns the FilterPipeline for the table.


setFilters

public void setFilters(FilterPipeline pipeline)
Sets the FilterPipeline for filtering table rows, maybe null to remove all previously applied filters. Note: the current "interactive" sortState is preserved (by internally copying the old sortKeys to the new pipeline, if any).

Parameters:
pipeline - the FilterPipeline to use, null removes all filters.

getFilterPipelineListener

protected PipelineListener getFilterPipelineListener()
returns the listener for changes in filters.


createPipelineListener

protected PipelineListener createPipelineListener()
creates the listener for changes in filters.


updateOnFilterContentChanged

protected void updateOnFilterContentChanged()
method called on change notification from filterpipeline.


setSortable

public void setSortable(boolean sortable)
Sets "sortable" property indicating whether or not this table supports sortable columns. If sortable is true then sorting will be enabled on all columns whose sortable property is true. If sortable is false then sorting will be disabled for all columns, regardless of each column's individual sorting property. The default is true.

Parameters:
sortable - boolean indicating whether or not this table supports sortable columns
See Also:
TableColumnExt.isSortable()

isSortable

public boolean isSortable()
Returns the table's sortable property.

Returns:
true if the table is sortable.

resetSortOrder

public void resetSortOrder()
Resets sorting of all columns.


toggleSortOrder

public void toggleSortOrder(int columnIndex)
Toggles the sort order of the column at columnIndex.

The exact behaviour is defined by the SortController's toggleSortOrder implementation. Typically a unsorted column is sorted in ascending order, a sorted column's order is reversed.

Respects the tableColumnExt's sortable and comparator properties: routes the column's comparator to the SortController and does nothing if !isSortable(column).

PRE: 0 <= columnIndex < getColumnCount()

Parameters:
columnIndex - the columnIndex in view coordinates.

isSortable

protected boolean isSortable(int columnIndex)
Decides if the column at columnIndex can be interactively sorted.

Here: true if both this table and the column sortable property is enabled, false otherwise.

Parameters:
columnIndex - column in view coordinates
Returns:
boolean indicating whether or not the column is sortable in this table.

setSortOrder

public void setSortOrder(int columnIndex,
SortOrder sortOrder)
Sorts the table by the given column using SortOrder. Respects the tableColumnExt's sortable and comparator properties: routes the column's comparator to the SortController and does nothing if !isSortable(column).

PRE: 0 <= columnIndex < getColumnCount()

Parameters:
columnIndex - the column index in view coordinates.
sortOrder - the sort order to use. If null or SortOrder.UNSORTED, this method has the same effect as resetSortOrder();

getSortOrder

public SortOrder getSortOrder(int columnIndex)
Returns the SortOrder of the given column.

Parameters:
columnIndex - the column index in view coordinates.
Returns:
the interactive sorter's SortOrder if matches the column or SortOrder.UNSORTED

toggleSortOrder

public void toggleSortOrder(Object identifier)
Toggles the sort order of the column with identifier.

The exact behaviour is defined by the SortController's toggleSortOrder implementation. Typically a unsorted column is sorted in ascending order, a sorted column's order is reversed.

Respects the tableColumnExt's sortable and comparator properties: routes the column's comparator to the SortController and does nothing if !isSortable(column).

PENDING: JW - define the behaviour if the identifier is not found. This can happen if either there's no column at all with the identifier or if there's no column of type TableColumnExt. Currently does nothing, that is does not change sort state.

Parameters:
identifier - the column identifier.

setSortOrder

public void setSortOrder(Object identifier,
SortOrder sortOrder)
Sorts the table by the given column using the SortOrder. Respects the tableColumnExt's sortable and comparator properties: routes the column's comparator to the SortController and does nothing if !isSortable(column).

PENDING: JW - define the behaviour if the identifier is not found. This can happen if either there's no column at all with the identifier or if there's no column of type TableColumnExt. Currently does nothing, that is does not change sort state.

Parameters:
identifier - the column's identifier.
sortOrder - the sort order to use. If null or SortOrder.UNSORTED, this method has the same effect as resetSortOrder();

getSortOrder

public SortOrder getSortOrder(Object identifier)
Returns the SortOrder of the given column. PENDING: JW - define the behaviour if the identifier is not found. This can happen if either there's no column at all with the identifier or if there's no column of type TableColumnExt. Currently returns SortOrder.UNSORTED.

Parameters:
identifier - the column's identifier.
Returns:
the interactive sorter's SortOrder if matches the column or SortOrder.UNSORTED

isSortable

protected boolean isSortable(Object identifier)
Decides if the column with identifier can be interactively sorted.

Here: true if both this table and the column sortable property is enabled, false otherwise.

Parameters:
identifier - the column's identifier
Returns:
boolean indicating whether or not the column is sortable in this table.

getSortController

protected SortController getSortController()
returns the currently active SortController. Can be null on the very first call after instantiation.

Returns:
the currently active SortController may be null

getSortedColumn

public TableColumn getSortedColumn()
Returns:
the currently interactively sorted TableColumn or null if there is not sorter active or if the sorted column index does not correspond to any column in the TableColumnModel.

columnRemoved

public void columnRemoved(TableColumnModelEvent e)
overridden to remove the interactive sorter if the sorted column is no longer contained in the ColumnModel.

Specified by:
columnRemoved in interface TableColumnModelListener
Overrides:
columnRemoved in class JTable
See Also:
TableColumnModelListener

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)

getVisibleRowCount

public int getVisibleRowCount()
Returns the preferred number of rows to show in a JScrollPane.

Returns:
the number of rows to show in a JScrollPane
See Also:
setVisibleRowCount(int)

setVisibleRowCount

public void setVisibleRowCount(int visibleRowCount)
Sets the preferred number of rows to show in a JScrollPane.

TODO JW - make bound property, reset scrollablePref(? distinguish internal from client code triggered like in rowheight?) and re-layout.

Parameters:
visibleRowCount - number of rows to show in a JScrollPane
See Also:
getVisibleRowCount()

getPreferredScrollableViewportSize

public Dimension getPreferredScrollableViewportSize()
Returns the preferred size of the viewport for this table.

TODO JW: refactor and comment.

Specified by:
getPreferredScrollableViewportSize in interface Scrollable
Overrides:
getPreferredScrollableViewportSize in class JTable
Returns:
a Dimension object containing the preferredSize of the JViewport which displays this table
See Also:
Scrollable.getPreferredScrollableViewportSize()

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)

scrollRowToVisible

public void scrollRowToVisible(int row)
Scrolls vertically to make the given row visible. This might not have any effect if the table isn't contained in a JViewport.

Note: this method has no precondition as it internally uses getCellRect which is lenient to off-range coordinates.

Parameters:
row - the view row index of the cell
See Also:
scrollColumnToVisible(int), scrollCellToVisible(int, int), JComponent.scrollRectToVisible(Rectangle)

scrollColumnToVisible

public void scrollColumnToVisible(int column)
Scrolls horizontally to make the given column visible. This might not have any effect if the table isn't contained in a JViewport.

Note: this method has no precondition as it internally uses getCellRect which is lenient to off-range coordinates.

Parameters:
column - the view column index of the cell
See Also:
scrollRowToVisible(int), scrollCellToVisible(int, int), JComponent.scrollRectToVisible(Rectangle)

scrollCellToVisible

public void scrollCellToVisible(int row,
int column)
Scrolls to make the cell at row and column visible. This might not have any effect if the table isn't contained in a JViewport.

Note: this method has no precondition as it internally uses getCellRect which is lenient to off-range coordinates.

Parameters:
row - the view row index of the cell
column - the view column index of the cell
See Also:
scrollColumnToVisible(int), scrollRowToVisible(int), JComponent.scrollRectToVisible(Rectangle)

getSelectionMode

public int getSelectionMode()
Returns the selection mode used by this table's selection model.

PENDING JW - setter?

Returns:
the selection mode used by this table's selection model
See Also:
ListSelectionModel.getSelectionMode()

getSearchable

public Searchable getSearchable()
Returns:
a not-null Searchable for this editor.

setSearchable

public void setSearchable(Searchable searchable)
sets the Searchable for this editor. If null, a default searchable will be used.

Parameters:
searchable -

getComponentAdapter

protected ComponentAdapter getComponentAdapter()
Returns:
the unconfigured ComponentAdapter.

getComponentAdapter

protected ComponentAdapter getComponentAdapter(int row,
int column)
Convenience to access a configured ComponentAdapter.

Parameters:
row - the row index in view coordinates.
column - the column index in view coordinates.
Returns:
the configured ComponentAdapter.

getHighlighters

public HighlighterPipeline getHighlighters()
Returns the HighlighterPipeline assigned to the table, null if none.

Returns:
the HighlighterPipeline assigned to the table.
See Also:
setHighlighters(HighlighterPipeline)

setHighlighters

public void setHighlighters(HighlighterPipeline pipeline)
Assigns a HighlighterPipeline to the table, maybe null to remove all Highlighters.

The default value is null.

Parameters:
pipeline - the HighlighterPipeline to use for renderer decoration.
See Also:
getHighlighters(), addHighlighter(Highlighter), removeHighlighter(Highlighter)

addHighlighter

public void addHighlighter(Highlighter highlighter)
Adds a Highlighter.

If the HighlighterPipeline returned from getHighlighters() is null, creates and sets a new pipeline containing the given Highlighter. Else, appends the Highlighter to the end of the pipeline.

Parameters:
highlighter - the Highlighter to add.
Throws:
NullPointerException - if Highlighter is null.
See Also:
removeHighlighter(Highlighter), setHighlighters(HighlighterPipeline)

removeHighlighter

public void removeHighlighter(Highlighter highlighter)
Removes the Highlighter.

Does nothing if the HighlighterPipeline is null or does not contain the given Highlighter.

Parameters:
highlighter - the highlighter to remove.
See Also:
addHighlighter(Highlighter), setHighlighters(HighlighterPipeline)

getHighlighterChangeListener

protected ChangeListener getHighlighterChangeListener()
Returns the ChangeListener to use with highlighters. Lazily creates the listener.

Returns:
the ChangeListener for observing changes of highlighters, guaranteed to be not-null

createHighlighterChangeListener

protected ChangeListener createHighlighterChangeListener()
Creates and returns the ChangeListener observing Highlighters.

Here: repaints the table on receiving a stateChanged.

Returns:
the ChangeListener defining the reaction to changes of highlighters.

getCellRenderer

public TableCellRenderer getCellRenderer(int row,
int column)
Returns an appropriate renderer for the cell specified by this row and column. If the TableColumn for this column has a non-null renderer, returns that. If not, finds the class of the data in this column (using getColumnClass) and returns the default renderer for this type of data.

Note: Throughout the table package, the internal implementations always use this method to provide renderers so that this default behavior can be safely overridden by a subclass.

Overridden to fix core bug #4614616 (NPE if TableModel's Class for the column is an interface). This method guarantees to always return a not null value. *

Overrides:
getCellRenderer in class JTable
Parameters:
row - the row of the cell to render, where 0 is the first row
column - the column of the cell to render, where 0 is the first column
Returns:
the assigned renderer; if null returns the default renderer for this type of object
See Also:
DefaultTableCellRenderer, TableColumn.setCellRenderer(javax.swing.table.TableCellRenderer), JTable.setDefaultRenderer(java.lang.Class, javax.swing.table.TableCellRenderer)

prepareRenderer

public Component prepareRenderer(TableCellRenderer renderer,
int row,
int column)
Returns the decorated Component used as a stamp to render the specified cell. Overrides superclass version to provide support for cell decorators.

Adjusts component orientation (guaranteed to happen before applying Highlighters).

Overrides:
prepareRenderer in class JTable
Parameters:
renderer - the TableCellRenderer to prepare
row - the row of the cell to render, where 0 is the first row
column - the column of the cell to render, where 0 is the first column
Returns:
the decorated Component used as a stamp to render the specified cell
See Also:
Highlighter

resetDefaultTableCellRendererColors

protected void resetDefaultTableCellRendererColors(Component renderer,
int row,
int column)
Method to hack around #258-swingx: apply a specialized Highlighter to force reset the color "memory" of DefaultTableCellRenderer. This is called for each renderer in prepareRenderer after calling super, but before applying the HighlighterPipeline. Subclasses which are sure to solve the problem at the core (that is in a well-behaved DefaultTableCellRenderer) should override this method to do nothing.

Parameters:
renderer - the TableCellRenderer to hack
row - the row of the cell to render
column - the column index of the cell to render
See Also:
ResetDTCRColorHighlighter, prepareRenderer(TableCellRenderer, int, int)

prepareEditor

public Component prepareEditor(TableCellEditor editor,
int row,
int column)
Prepares the editor by querying the data model for the value and selection state of the cell at row, column.

Note: Throughout the table package, the internal implementations always use this method to prepare editors so that this default behavior can be safely overridden by a subclass.

Overridden to adjust the editor's component orientation if appropriate.

Overrides:
prepareEditor in class JTable
Parameters:
editor - the TableCellEditor to set up
row - the row of the cell to edit, where 0 is the first row
column - the column of the cell to edit, where 0 is the first column
Returns:
the Component being edited

adjustComponentOrientation

protected void adjustComponentOrientation(Component stamp)
Adjusts the Component's orientation to this JXTable's CO if appropriate. The parameter must not be null.

This implementation synchs the CO always.

Parameters:
stamp - the Component who's CO may need to be synched.

getNewDefaultRenderer

public TableCellRenderer getNewDefaultRenderer(Class columnClass)
Returns a new instance of the default renderer for the specified class. This differs from getDefaultRenderer() in that it returns a new instance each time so that the renderer may be set and customized on a particular column.

Parameters:
columnClass - Class of value being rendered
Returns:
TableCellRenderer instance which renders values of the specified type

createDefaultRenderers

protected void createDefaultRenderers()
Creates default cell renderers for objects, numbers, doubles, dates, booleans, icons, and links.

Overridden so we can act as factory for renderers plus hacking around huge memory consumption of UIDefaults (see #6345050 in core Bug parade)

Creates default cell renderers for objects, numbers, doubles, dates, booleans, and icons.

Overrides:
createDefaultRenderers in class JTable
See Also:
DefaultTableCellRenderer

createDefaultEditors

protected void createDefaultEditors()
Creates default cell editors for objects, numbers, and boolean values.

Overridden to hook enhanced editors plus hacking around huge memory consumption of UIDefaults (see #6345050 in core Bug parade)

Overrides:
createDefaultEditors in class JTable
See Also:
DefaultCellEditor

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)

isTerminateEditOnFocusLost

public boolean isTerminateEditOnFocusLost()
Returns the property which determines the edit termination behaviour on focus lost.

Returns:
boolean to indicate whether an ongoing edit should be terminated if the focus is moved to somewhere outside of the table.
See Also:
setTerminateEditOnFocusLost(boolean)

setTerminateEditOnFocusLost

public void setTerminateEditOnFocusLost(boolean terminate)
Sets the property to determine whether an ongoing edit should be terminated if the focus is moved to somewhere outside of the table. If true, terminates the edit, does nothing otherwise. The exact behaviour is implemented in JTable.CellEditorRemover: "outside" is interpreted to be on a component which is not under the table hierarchy but inside the same toplevel window, "terminate" does so in any case, first tries to stop the edit, if that's unsuccessful it cancels the edit.

The default value is true.

Parameters:
terminate - the flag to determine whether or not to terminate the edit
See Also:
isTerminateEditOnFocusLost()

isAutoStartEditOnKeyStroke

public boolean isAutoStartEditOnKeyStroke()
Returns the autoStartsEdit property.

Returns:
boolean to indicate whether a keyStroke should try to start editing.
See Also:
setAutoStartEditOnKeyStroke(boolean)

setAutoStartEditOnKeyStroke

public void setAutoStartEditOnKeyStroke(boolean autoStart)
Sets the autoStartsEdit property. If true, keystrokes are passed-on to the cellEditor of the lead cell to let it decide whether to start an edit.

The default value is true.

Parameters:
autoStart - boolean to determine whether a keyStroke should try to start editing.
See Also:
isAutoStartEditOnKeyStroke()

updateUI

public void updateUI()
Notification from the UIManager that the L&F has changed. Replaces the current UI object with the latest version from the UIManager.

Additionally updates auto-adjusted row height and highlighters.

Another of the override motivation is to fix core issue (?? ID): super fails to update all renderers/editors.

Overrides:
updateUI in class JTable
See Also:
JComponent.updateUI()

updateHighlighters

protected void updateHighlighters()
Updates highlighter after updateUI changes.

See Also:
Highlighter.UIHighlighter

updateRowHeightUI

protected void updateRowHeightUI(boolean respectRowSetFlag)
Auto-adjusts rowHeight to something more pleasing then the default. This method is called after instantiation and after updating the UI. Does nothing if the given parameter is true and the rowHeight had been already set by client code. The underlying problem is that raw types can't implement UIResource.

This implementation asks the UIManager for a default value (stored with key "JXTable.rowHeight"). If none is available, calculates a "reasonable" height from the table's fontMetrics, assuming that most renderers/editors will have a border with top/bottom of 1.

Parameters:
respectRowSetFlag - a boolean to indicate whether client-code flag should be respected.
See Also:
isXTableRowHeightSet

setDefaultMargins

public void setDefaultMargins(boolean showHorizontalLines,
boolean showVerticalLines)
Convenience to set both grid line visibility and default margin for horizontal/vertical lines. The margin defaults to 1 or 0 if the grid lines are drawn or not drawn.

PENDING rename? setShowGrid(boolean, boolean) would let it appear nearer to the other setShowGrid method.

Parameters:
showHorizontalLines - boolean to decide whether to draw horizontal grid lines.
showVerticalLines - boolean to decide whether to draw vertical grid lines.
See Also:
JTable.setShowGrid(boolean), JTable.setIntercellSpacing(Dimension)

setRowHeight

public void setRowHeight(int rowHeight)
Sets the height, in pixels, of all cells to rowHeight, revalidates, and repaints. The height of the cells will be equal to the row height minus the row margin.

Overriden to keep view/model coordinates of SizeSequence in synch. Marks the request as client-code induced.

Overrides:
setRowHeight in class JTable
Parameters:
rowHeight - new row height
See Also:
isXTableRowHeightSet

setRowHeight

public void setRowHeight(int row,
int rowHeight)
Sets the height for row to rowHeight, revalidates, and repaints. The height of the cells in this row will be equal to the row height minus the row margin.

Does nothing if support of individual rowHeights is not enabled. Overriden to keep view/model coordinates of SizeSequence in synch.

Overrides:
setRowHeight in class JTable
Parameters:
row - the row whose height is being changed
rowHeight - new row height, in pixels
See Also:
isRowHeightEnabled()

setRowHeightEnabled

public void setRowHeightEnabled(boolean enabled)
Sets enablement of individual rowHeight support. Enabling the support involves reflective access to super's private field rowModel which may fail due to security issues. If failing the support is not enabled.

The default value is false.

Parameters:
enabled - a boolean to indicate whether per-row heights should be enabled.
See Also:
isRowHeightEnabled(), setRowHeight(int, int)

isRowHeightEnabled

public boolean isRowHeightEnabled()
Returns a boolean to indicate whether individual row height is enabled.

Returns:
a boolean to indicate whether individual row height support is enabled.
See Also:
setRowHeightEnabled(boolean), setRowHeight(int, int)

getRowModelMapper

protected SizeSequenceMapper getRowModelMapper()
Returns the mapper used synch individual rowHeights in view/model coordinates.

Returns:
the SizeSequenceMapper used to synch view/model coordinates for individual row heights
See Also:
SizeSequenceMapper

adminSetRowHeight

protected void adminSetRowHeight(int rowHeight)
Sets the rowHeight for all rows to the given value. Keeps the flag isXTableRowHeight unchanged. This enables the distinction between setting the height for internal reasons from doing so by client code.

Parameters:
rowHeight - new height in pixel.
See Also:
setRowHeight(int), isXTableRowHeightSet

rowAtPoint

public int rowAtPoint(Point point)
Returns the index of the row that point lies in, or -1 if the result is not in the range [0, getRowCount()-1].

Overridden to work around core Bug (ID #6291631): negative y is mapped to row 0).

Overrides:
rowAtPoint in class JTable
Parameters:
point - the location of interest
Returns:
the index of the row that point lies in, or -1 if the result is not in the range [0, getRowCount()-1]
See Also:
JTable.columnAtPoint(java.awt.Point)

createDefaultTableHeader

protected JTableHeader createDefaultTableHeader()
Returns the default table header object, which is a JTableHeader. A subclass can override this method to return a different table header object.

Overridden to return a JXTableHeader.

Overrides:
createDefaultTableHeader in class JTable
Returns:
the default table header object
See Also:
JXTableHeader

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