swingx
Version 2005-08-19

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

A JXTable is a JTable with built-in support for row sorting, filtering, and highlighting, column visibility and a special popup control on the column header for quick access to table configuration. You can instantiate a JXTable just as you would a JTable, using a TableModel. However, a JXTable automatically wraps TableColumns inside a TableColumnExt instance. TableColumnExt supports visibility, sortability, and prototype values for column sizing, none of which are available in TableColumn. You can retrieve the TableColumnExt instance for a column using getColumnExt(Object) or getColumnExt(int colnumber).

A JXTable is, by default, sortable by clicking on column headers; each subsequent click on a header reverses the order of the sort, and a sort arrow icon is automatically drawn on the header. Sorting can be disabled using setSortable(boolean). Sorting on columns is handled by a Sorter instance which contains a Comparator used to compare values in two rows of a column. You can replace the Comparator for a given column by using getColumnExt("column").getSorter().setComparator(customComparator)

Columns can be hidden or shown by setting the visible property on the TableColumnExt using TableColumnExt.setVisible(boolean). Columns can also be shown or hidden from the column control popup.

The column control popup is triggered by an icon drawn to the far right of the column headers, above the table's scrollbar (when installed in a JScrollPane). The popup allows the user to select which columns should be shown or hidden, as well as to pack columns and turn on horizontal scrolling. To show or hide the column control, use the setColumnControlVisible(boolean show)method.

Rows can be filtered from a JXTable using a Filter class and a FilterPipeline. One assigns a FilterPipeline to the table using setFilters(FilterPipeline). Filtering hides, but does not delete or permanently remove rows from a JXTable. Filters are used to provide sorting to the table--rows are not removed, but the table is made to believe rows in the model are in a sorted order.

One can automatically highlight certain rows in a JXTable by attaching Highlighters in the setHighlighters(HighlighterPipeline)method. An example would be a Highlighter that colors alternate rows in the table for readability; AlternateRowHighlighter does this. Again, like Filters, Highlighters can be chained together in a HighlighterPipeline to achieve more interesting effects.

You can resize all columns, selected columns, or a single column using the methods like packAll(). Packing combines several other aspects of a JXTable. If horizontal scrolling is enabled using setHorizontalScrollEnabled(boolean), then the scrollpane will allow the table to scroll right-left, and columns will be sized to their preferred size. To control the preferred sizing of a column, you can provide a prototype value for the column in the TableColumnExt using TableColumnExt.setPrototypeValue(Object). The prototype is used as an indicator of the preferred size of the column. This can be useful if some data in a given column is very long, but where the resize algorithm would normally not pick this up.

Last, you can also provide searches on a JXTable using the Searchable property.

Keys/Actions registered with this component:

Key bindings.

Client Properties.

See Also:
Serialized Form

Nested Class Summary
static class JXTable.BooleanEditor
           
static class JXTable.BooleanRenderer
           
static class JXTable.DateRenderer
           
static class JXTable.DoubleRenderer
           
static class JXTable.GenericEditor
          Default Editors
static class JXTable.IconRenderer
           
static class JXTable.NumberEditor
           
static class JXTable.NumberRenderer
           
protected static class JXTable.TableAdapter
           
static class JXTable.TableRolloverController<T extends JTable>
          listens to rollover properties.
 class JXTable.TableSearchable
           
 
Nested classes/interfaces inherited from class javax.swing.JTable
JTable.AccessibleJTable, JTable.PrintMode
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  ComponentAdapter dataAdapter
          The ComponentAdapter for model data access.
protected  FilterPipeline filters
          The FilterPipeline for the table.
protected  HighlighterPipeline highlighters
          The HighlighterPipeline for the table.
static String HORIZONTALSCROLL_ACTION_COMMAND
          Constant string for horizontal scroll actions, used in JXTable's Action Map.
protected  boolean isXTableRowHeightSet
          temporary hack: rowheight will be internally adjusted to font size on instantiation and in updateUI if the height has not been set explicitly by the application.
static String MATCH_HIGHLIGHTER
          key for client property to use SearchHighlighter as match marker.
static String PACKALL_ACTION_COMMAND
          Constant string for packing all columns, used in JXTable's Action Map.
static String PACKSELECTED_ACTION_COMMAND
          Constant string for packing selected columns, used in JXTable's Action Map.
protected  Searchable searchable
           
static String UIPREFIX
          The prefix marker to find component related properties in the resourcebundle.
 
Fields inherited from class javax.swing.JTable
AUTO_RESIZE_ALL_COLUMNS, AUTO_RESIZE_LAST_COLUMN, AUTO_RESIZE_NEXT_COLUMN, AUTO_RESIZE_OFF, AUTO_RESIZE_SUBSEQUENT_COLUMNS, autoCreateColumnsFromModel, autoResizeMode, cellEditor, cellSelectionEnabled, columnModel, dataModel, defaultEditorsByColumnClass, defaultRenderersByColumnClass, editingColumn, editingRow, editorComp, gridColor, preferredViewportSize, rowHeight, rowMargin, rowSelectionAllowed, selectionBackground, selectionForeground, selectionModel, showHorizontalLines, showVerticalLines, tableHeader
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
JXTable()
          Instantiates a JXTable with a default table model, no data.
JXTable(int numRows, int numColumns)
          Instantiates a JXTable for a given number of columns and rows.
JXTable(Object[][] rowData, Object[] columnNames)
          Instantiates a JXTable with data in a array or rows and column names.
JXTable(TableModel dm)
          Instantiates a JXTable with a specific table model.
JXTable(TableModel dm, TableColumnModel cm)
          Instantiates a JXTable with a specific table model.
JXTable(TableModel dm, TableColumnModel cm, ListSelectionModel sm)
          Instantiates a JXTable with a specific table model, column model, and selection model.
JXTable(Vector rowData, Vector columnNames)
          Instantiates a JXTable with data in a vector or rows and column names.
 
Method Summary
 void addHighlighter(Highlighter highlighter)
          Adds a Highlighter.
protected  void adjustComponentOrientation(Component stamp)
          adjusts the Component's orientation to JXTable's CO if appropriate.
protected  void adminSetRowHeight(int rowHeight)
          calling setRowHeight for internal reasons.
 void columnRemoved(TableColumnModelEvent e)
          overridden to remove the interactive sorter if the sorted column is no longer contained in the ColumnModel.
 void columnSelectionChanged(ListSelectionEvent e)
          Notifies the table that a new column has been selected.
protected  void configureEnclosingScrollPane()
          overridden to addionally configure the upper right corner of an enclosing scrollpane with the ColumnControl.
protected  void configureViewportBackground()
          Deprecated. no longer used - replaced by fillsViewportHeight
 int convertRowIndexToModel(int row)
          Convert row index from view coordinates to model coordinates accounting for the presence of sorters and filters.
 int convertRowIndexToView(int row)
          Convert row index from model coordinates to view coordinates accounting for the presence of sorters and filters.
protected  TableColumn createAndConfigureColumn(TableModel model, int modelColumn)
           
protected  TableColumnModel createDefaultColumnModel()
          ?
 void createDefaultColumnsFromModel()
           
protected  void createDefaultEditors()
          Creates default cell editors for objects, numbers, and boolean values.
protected  void createDefaultRenderers()
          Creates default cell renderers for objects, numbers, doubles, dates, booleans, icons, and links.
protected  JTableHeader createDefaultTableHeader()
          ?
protected  JXTable.TableRolloverController createLinkController()
           
protected  PipelineListener createPipelineListener()
          creates the listener for changes in filters.
protected  RolloverProducer createRolloverProducer()
          creates and returns the RolloverProducer to use.
 TableColumn getColumn(int viewColumnIndex)
          Returns the TableColumn object for the column in the table whose column index is equal to viewColumnIndex.
 JComponent getColumnControl()
          returns the component for column control.
 int getColumnCount(boolean includeHidden)
          returns the number of TableColumns including hidden if the parameter is set to true.
 TableColumnExt getColumnExt(int viewColumnIndex)
          Returns the TableColumnExt object for the column in the table whose column index is equal to viewColumnIndex or null if the column is not of type TableColumnExt
 TableColumnExt getColumnExt(Object identifier)
          Returns the TableColumnExt object for the column in the table whose identifier is equal to identifier, when compared using equals.
protected  ColumnFactory getColumnFactory()
           
 int getColumnMargin()
          Returns the margin between columns.
 List getColumns()
          returns a list of all visible TableColumns.
 List getColumns(boolean includeHidden)
          returns a list of TableColumns including hidden if the parameter is set to true.
protected  ComponentAdapter getComponentAdapter()
           
 boolean getFillsViewportHeight()
          Returns the flag to control JXTable scrollableTracksViewportHeight property.
protected  PipelineListener getFilterPipelineListener()
          returns the listener for changes in filters.
 FilterPipeline getFilters()
          Returns the FilterPipeline for the table.
 HighlighterPipeline getHighlighters()
          Returns the HighlighterPipeline assigned to the table, null if none.
protected  JXTable.TableRolloverController getLinkController()
           
 TableCellRenderer getNewDefaultRenderer(Class columnClass)
          Returns a new instance of the default renderer for the specified class.
 Dimension getPreferredScrollableViewportSize()
           
 int getRowCount()
          Returns the row count in the table; if filters are applied, this is the filtered row count.
protected  SizeSequenceMapper getRowModelMapper()
           
 boolean getScrollableTracksViewportHeight()
          Overridden to control the tracksHeight property depending on fillsViewportHeight and relative size to containing parent (viewport?).
 Searchable getSearchable()
           
protected  SelectionMapper getSelectionMapper()
          temporaryly exposed for testing...
 int getSelectionMode()
          Returns the selection mode used by this table's selection model.
protected  SortController getSortController()
          returns the currently active SortController.
 TableColumn getSortedColumn()
           
 SortOrder getSortOrder(int columnIndex)
          Returns the SortOrder of the interactive sorter if it is set from the given column.
 Object getValueAt(int row, int column)
          
 int getVisibleRowCount()
          ?
protected  void init()
          Initializes the table for use.
protected  void initializeColumnPreferredWidth(TableColumn column)
          Initialize the preferredWidth of the specified column based on the column's prototypeValue property.
 boolean isCellEditable(int row, int column)
          Overridden to account for row index mapping and to respect TableColumnExt.isEditable() property.
 boolean isColumnControlVisible()
          returns visibility flag of column control.
 boolean isHierarchical(int column)
           
 boolean isRolloverEnabled()
          Returns the rolloverEnabled property.
 boolean isRowHeightEnabled()
           
 boolean isSortable()
          Returns true if the table is sortable.
 void packAll()
          This resizes all columns to fit the viewport; if horizontal scrolling is enabled, all columns will get their preferred width.
 void packColumn(int column, int margin)
          Packs an indivudal column in the table.
 void packColumn(int column, int margin, int max)
          Packs an indivual column in the table to less than or equal to the maximum witdth.
 void packSelected()
          This resizes selected columns to fit the viewport; if horizontal scrolling is enabled, selected columns will get their preferred width.
 void packTable(int margin)
          Packs all the columns to their optimal size.
 Component prepareEditor(TableCellEditor editor, int row, int column)
          Overridden to adjust the editor's component orientation if appropriate.
 Component prepareRenderer(TableCellRenderer renderer, int row, int column)
          Returns the decorated Component used as a stamp to render the specified cell.
protected  void removeColumns()
          Remove all columns, make sure to include hidden.
 void removeHighlighter(Highlighter highlighter)
          Removes the Highlighter.
 void resetSortOrder()
          Removes the interactive sorter.
 int rowAtPoint(Point point)
          workaround bug in JTable.
 void scrollCellToVisible(int row, int column)
          Scrolls to make the cell at row and column visible.
 void scrollColumnToVisible(int column)
          Scrolls horizontally to make the given column visible.
 void scrollRowToVisible(int row)
          Scrolls vertically to make the given row visible.
 void setAutoResizeMode(int mode)
          overridden to update the show horizontal scrollbar action's selected state.
 void setColumnControlVisible(boolean showColumnControl)
          bound property to flag visibility state of column control.
 void setColumnMargin(int value)
          Sets the margin between columns.
 void setColumnSequence(Object[] identifiers)
          reorders the columns in the sequence given array.
 void setComponentOrientation(ComponentOrientation o)
          Hack around core swing JScrollPane bug: can't cope with corners when changing component orientation at runtime.
 void setFillsViewportHeight(boolean fillsViewportHeight)
          Set flag to control JXTable's scrollableTracksViewportHeight property.
 void setFilters(FilterPipeline pipeline)
          Sets the FilterPipeline for filtering table rows.
 void setHighlighters(HighlighterPipeline pipeline)
          Assigns a HighlighterPipeline to the table. bound property.
 void setHorizontalScrollEnabled(boolean enabled)
          Controls horizontal scrolling in the viewport, and works in coordination with column sizing.
 void setModel(TableModel newModel)
          
 void setRolloverEnabled(boolean rolloverEnabled)
          Property to enable/disable rollover support.
 void setRowHeight(int rowHeight)
          Changes the row height for all rows in the table.
 void setRowHeight(int row, int rowHeight)
           
 void setRowHeightEnabled(boolean enabled)
          sets enabled state of individual rowHeight support.
 void setSearchable(Searchable searchable)
          sets the Searchable for this editor.
 void setSelectionModel(ListSelectionModel newModel)
          Overridden to update selectionMapper
 void setSortable(boolean sortable)
          Sets "sortable" property indicating whether or not this table supports sortable columns.
 void setValueAt(Object aValue, int row, int column)
          
 void setVisibleRowCount(int visibleRowCount)
          ?
 void tableChanged(TableModelEvent e)
          additionally updates filtered state.
 void toggleSortOrder(int columnIndex)
          request to sort the column at columnIndex.
protected  void updateHighlighters()
           
protected  void updateOnFilterContentChanged()
          method called on change notification from filterpipeline.
 void updateUI()
          bug fix: super doesn't update all renderers/editors.
protected  void updateViewSizeSequence()
          Called if individual row height mapping need to be updated.
 
Methods inherited from class javax.swing.JTable
addColumn, addColumnSelectionInterval, addNotify, addRowSelectionInterval, changeSelection, clearSelection, columnAdded, columnAtPoint, columnMarginChanged, columnMoved, convertColumnIndexToModel, convertColumnIndexToView, createDefaultDataModel, createDefaultSelectionModel, createScrollPaneForTable, doLayout, editCellAt, editCellAt, editingCanceled, editingStopped, getAccessibleContext, getAutoCreateColumnsFromModel, getAutoResizeMode, getCellEditor, getCellEditor, getCellRect, getCellRenderer, getCellSelectionEnabled, getColumn, getColumnClass, getColumnCount, getColumnModel, getColumnName, getColumnSelectionAllowed, getDefaultEditor, getDefaultRenderer, getDragEnabled, getEditingColumn, getEditingRow, getEditorComponent, getGridColor, getIntercellSpacing, getModel, getPrintable, getRowHeight, getRowHeight, getRowMargin, getRowSelectionAllowed, getScrollableBlockIncrement, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedColumn, getSelectedColumnCount, getSelectedColumns, getSelectedRow, getSelectedRowCount, getSelectedRows, getSelectionBackground, getSelectionForeground, getSelectionModel, getShowHorizontalLines, getShowVerticalLines, getSurrendersFocusOnKeystroke, getTableHeader, getToolTipText, getUI, getUIClassID, initializeLocalVars, isCellSelected, isColumnSelected, isEditing, isRowSelected, moveColumn, paramString, print, print, print, print, processKeyBinding, removeColumn, removeColumnSelectionInterval, removeEditor, removeNotify, removeRowSelectionInterval, resizeAndRepaint, selectAll, setAutoCreateColumnsFromModel, setCellEditor, setCellSelectionEnabled, setColumnModel, setColumnSelectionAllowed, setColumnSelectionInterval, setDefaultEditor, setDefaultRenderer, setDragEnabled, setEditingColumn, setEditingRow, setGridColor, setIntercellSpacing, setPreferredScrollableViewportSize, setRowMargin, setRowSelectionAllowed, setRowSelectionInterval, setSelectionBackground, setSelectionForeground, setSelectionMode, setShowGrid, setShowHorizontalLines, setShowVerticalLines, setSurrendersFocusOnKeystroke, setTableHeader, setUI, sizeColumnsToFit, sizeColumnsToFit, unconfigureEnclosingScrollPane, valueChanged
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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.


dataAdapter

protected ComponentAdapter dataAdapter
The ComponentAdapter for model data access.


isXTableRowHeightSet

protected boolean isXTableRowHeightSet
temporary hack: rowheight will be internally adjusted to font size on instantiation and in updateUI if the height has not been set explicitly by the application.


searchable

protected Searchable searchable
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

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.

configureEnclosingScrollPane

protected void configureEnclosingScrollPane()
overridden to addionally configure the upper right corner of an enclosing scrollpane with the ColumnControl.

Overrides:
configureEnclosingScrollPane in class JTable

configureViewportBackground

protected void configureViewportBackground()
Deprecated. no longer used - replaced by fillsViewportHeight

set's the viewports background to this.background.

PENDING: need to repeat on background changes to this!


setComponentOrientation

public void setComponentOrientation(ComponentOrientation o)
Hack around core swing JScrollPane bug: can't cope with corners when changing component orientation at runtime. overridden to re-configure the columnControl.

Overrides:
setComponentOrientation in class Component

isColumnControlVisible

public boolean isColumnControlVisible()
returns visibility flag of column control.

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.

Returns:
true if the column is visible, false otherwise

getColumnControl

public JComponent getColumnControl()
returns the component for column control.

Returns:
component for column control

setColumnControlVisible

public void setColumnControlVisible(boolean showColumnControl)
bound property to flag visibility state of column control.

Parameters:
showColumnControl -

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.


setHorizontalScrollEnabled

public void setHorizontalScrollEnabled(boolean enabled)
Controls horizontal scrolling in the viewport, and works in coordination with column sizing.

Parameters:
enabled - If true, the scrollpane will allow the table to scroll horizontally, and columns will resize to their preferred width. If false, columns will resize to fit the viewport.

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

setAutoResizeMode

public void setAutoResizeMode(int mode)
overridden to update the show horizontal scrollbar action's selected state.

Overrides:
setAutoResizeMode in class JTable

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

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)

Overrides:
getValueAt in class JTable

setValueAt

public void setValueAt(Object aValue,
                       int row,
                       int column)

Overrides:
setValueAt in class JTable

isCellEditable

public boolean isCellEditable(int row,
                              int column)
Overridden to account for row index mapping and to respect TableColumnExt.isEditable() property.

Overrides:
isCellEditable in class JTable

setSelectionModel

public void setSelectionModel(ListSelectionModel newModel)
Overridden to update selectionMapper

Overrides:
setSelectionModel in class JTable

setModel

public void setModel(TableModel newModel)

Overrides:
setModel in class JTable

tableChanged

public void tableChanged(TableModelEvent e)
additionally updates filtered state.

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

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

protected SelectionMapper getSelectionMapper()
temporaryly exposed for testing...

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.


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 true if the table is sortable.


resetSortOrder

public void resetSortOrder()
Removes the interactive sorter. Used by headerListener.


toggleSortOrder

public void toggleSortOrder(int columnIndex)
request to sort the column at columnIndex. If there is already an interactive sorter for this column it's sort order is reversed. Otherwise the columns sorter is used as is. Used by headerListener. PRE: 0 <= columnIndex < getColumnCount()

Parameters:
columnIndex - the columnIndex in view coordinates.

getSortOrder

public SortOrder getSortOrder(int columnIndex)
Returns the SortOrder of the interactive sorter if it is set from the given column. Used by ColumnHeaderRenderer.getTableCellRendererComponent().

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

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

removeColumns

protected void removeColumns()
Remove all columns, make sure to include hidden.


getColumns

public List getColumns()
returns a list of all visible TableColumns.

Returns:
list of all the visible TableColumns

getColumns

public List getColumns(boolean includeHidden)
returns a list of TableColumns including hidden if the parameter is set to true.

Parameters:
includeHidden -
Returns:
list of TableColumns including hidden columns if specified

getColumnCount

public int getColumnCount(boolean includeHidden)
returns the number of TableColumns including hidden if the parameter is set to true.

Parameters:
includeHidden -
Returns:
number of TableColumns including hidden columns if specified

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.

Parameters:
identifiers - array of logical column names

getColumnExt

public TableColumnExt getColumnExt(Object identifier)
Returns the TableColumnExt object for the column in the table whose identifier is equal to identifier, when compared using equals. The returned TableColumn is guaranteed to be part of the current ColumnModel but may be hidden, that is
 
 TableColumnExt column = table.getColumnExt(id);
 if (column != null) {
     int viewIndex = table.convertColumnIndexToView(column.getModelIndex());
     assertEquals(column.isVisible(), viewIndex >= 0);
 }
  

Parameters:
identifier - the identifier object
Returns:
the TableColumnExt object that matches the identifier or null if none is found.

getColumnExt

public TableColumnExt getColumnExt(int viewColumnIndex)
Returns the TableColumnExt object for the column in the table whose column index is equal to viewColumnIndex or null if the column is not of type TableColumnExt

Parameters:
viewColumnIndex - index of the column with the object in question
Returns:
the TableColumnExt object that matches the column index
Throws:
ArrayIndexOutOfBoundsException - if viewColumnIndex out of allowed range.

getColumn

public TableColumn getColumn(int viewColumnIndex)
Returns the TableColumn object for the column in the table whose column index is equal to viewColumnIndex. Note: 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 object which will call the getColumn(Object) method ... We do here.

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.

createDefaultColumnsFromModel

public void createDefaultColumnsFromModel()
Overrides:
createDefaultColumnsFromModel in class JTable

createAndConfigureColumn

protected TableColumn createAndConfigureColumn(TableModel model,
                                               int modelColumn)

getColumnFactory

protected ColumnFactory getColumnFactory()

getColumnMargin

public int getColumnMargin()
Returns the margin between columns.

Returns:
the margin between columns

setColumnMargin

public void setColumnMargin(int value)
Sets the margin between columns.

Parameters:
value - margin between columns; must be greater than or equal to zero.

getSelectionMode

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

Returns:
the selection mode used by this table's selection model

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 -

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

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

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

setVisibleRowCount

public void setVisibleRowCount(int visibleRowCount)
?


getVisibleRowCount

public int getVisibleRowCount()
?


getPreferredScrollableViewportSize

public Dimension getPreferredScrollableViewportSize()
Specified by:
getPreferredScrollableViewportSize in interface Scrollable
Overrides:
getPreferredScrollableViewportSize in class JTable

packTable

public void packTable(int margin)
Packs all the columns to their optimal size. Works best with auto resizing turned off. Contributed by M. Hillary (Issue #60)

Parameters:
margin - the margin to apply to each column.

packColumn

public void packColumn(int column,
                       int margin)
Packs an indivudal column in the table. Contributed by M. Hillary (Issue #60)

Parameters:
column - The Column index to pack in View Coordinates
margin - The Margin to apply to the column width.

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 maximun is -1 then the column is made as wide as it needs. Contributed by M. Hillary (Issue #60)

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 mean any size.

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.

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

getComponentAdapter

protected ComponentAdapter getComponentAdapter()

getHighlighters

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


setHighlighters

public void setHighlighters(HighlighterPipeline pipeline)
Assigns a HighlighterPipeline to the table. bound property.


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 - must not be null.
Throws:
NullPointerException - if highlighter is null.

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.

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). see - https://swingx.dev.java.net/issues/show_bug.cgi?id=145

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

prepareEditor

public Component prepareEditor(TableCellEditor editor,
                               int row,
                               int column)
Overridden to adjust the editor's component orientation if appropriate.

Overrides:
prepareEditor in class JTable

adjustComponentOrientation

protected void adjustComponentOrientation(Component stamp)
adjusts the Component's orientation to JXTable's CO if appropriate. Here: always.

Parameters:
stamp -

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. PENDING: must not return null!

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. THINK: delegate to TableCellRenderers? Overridden so we can act as factory for renderers plus hacking around huge memory consumption of UIDefaults (see #6345050 in core Bug parade)

Overrides:
createDefaultRenderers in class JTable

createDefaultEditors

protected void createDefaultEditors()
Creates default cell editors for objects, numbers, and boolean values. Overridden to hacking around huge memory consumption of UIDefaults (see #6345050 in core Bug parade)

Overrides:
createDefaultEditors in class JTable
See Also:
DefaultCellEditor

updateUI

public void updateUI()
bug fix: super doesn't update all renderers/editors.

Overrides:
updateUI in class JTable

updateHighlighters

protected void updateHighlighters()

setRowHeight

public void setRowHeight(int rowHeight)
Changes the row height for all rows in the table.

Overrides:
setRowHeight in class JTable

setRowHeight

public void setRowHeight(int row,
                         int rowHeight)
Overrides:
setRowHeight in class JTable

setRowHeightEnabled

public void setRowHeightEnabled(boolean enabled)
sets enabled state of individual rowHeight support. The default is false. Enabling the support envolves reflective access to super's private field rowModel which may fail due to security issues. If failing the support is not enabled. PENDING: should we throw an Exception if the enabled fails? Or silently fail - depends on runtime context, can't do anything about it.

Parameters:
enabled -

isRowHeightEnabled

public boolean isRowHeightEnabled()

getRowModelMapper

protected SizeSequenceMapper getRowModelMapper()
Returns:
SizeSequenceMapper

adminSetRowHeight

protected void adminSetRowHeight(int rowHeight)
calling setRowHeight for internal reasons. Keeps the isXTableRowHeight unchanged.


rowAtPoint

public int rowAtPoint(Point point)
workaround bug in JTable. (Bug Parade ID #6291631 - negative y is mapped to row 0).

Overrides:
rowAtPoint in class JTable

createDefaultTableHeader

protected JTableHeader createDefaultTableHeader()
?

Overrides:
createDefaultTableHeader in class JTable

createDefaultColumnModel

protected TableColumnModel createDefaultColumnModel()
?

Overrides:
createDefaultColumnModel in class JTable

swingx
Version 2005-08-19