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, TableColumnModelExtListener
Direct Known Subclasses:
JXTreeTable

public class JXTable
extends JTable
implements TableColumnModelExtListener

Enhanced Table component with support for general SwingX sorting/filtering, rendering, highlighting, rollover and search functionality. Table specific enhancements include runtime configuration options like toggle column visibility, column sizing, PENDING JW ...

Sorting and Filtering

JXTable supports sorting and filtering of rows. Sorting support is single column only. It provides api to apply a specific sort order or to toggle the sort order of columns identified by view index or column identifier or reset all sorts.

 table.setSortOrder("PERSON_ID", SortOrder.DESCENDING);
 table.toggleSortOder(4);
 table.resetSortOrder();
 
Sorting sequence can be configured per column by setting the TableColumnExt's "comparator" property. Sorting can be disabled per column or per table by setSortable(boolean).

Typically, a JXTable is sortable by left clicking on column headers. By default, each subsequent click on a header reverses the order of the sort, and a sort arrow icon is automatically drawn on the header. The exact mapping of a user gesture to a sort effect is configurable by installing a custom SortGestureRecognizer on the JXTableHeader.

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 nor 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. NOTE: SwingX sorting/filtering is incompatible with core sorting/filtering in JDK 6+. Will be replaced by core functionality after switching the target jdk version from 5 to 6.

Rendering and Highlighting

As all SwingX collection views, a JXTable is a HighlighterClient (PENDING JW: formally define and implement, like in AbstractTestHighlighter), that is it provides consistent api to add and remove Highlighters which can visually decorate the rendering component.

An example multiple highlighting (default striping as appropriate for the current LookAndFeel, cell foreground on matching pattern, and shading a column):


 
 Highlighter simpleStriping = HighlighterFactory.createSimpleStriping();
 PatternPredicate patternPredicate = new PatternPredicate("ˆM", 1);
 ColorHighlighter magenta = new ColorHighlighter(patternPredicate, null,
       Color.MAGENTA, null, Color.MAGENTA);
 Highlighter shading = new ShadingColorHighlighter(
       new HighlightPredicate.ColumnHighlightPredicate(1));
 
 table.setHighlighters(simpleStriping,
        magenta,
        shading);
 

To fully support, JXTable registers SwingX default table renderers instead of core defaults (see DefaultTableRenderer) The recommended approach for customizing rendered content it to intall a DefaultTableRenderer configured with a custom String- and/or IconValue. F.i. assuming the cell value is a File and should be rendered by showing its name followed and date of last change:


 StringValue sv = new StringValue() {
      public String getString(Object value) {
        if (!(value instanceof File)) return StringValues.TO_STRING.getString(value);
        return StringValues.FILE_NAME.getString(value) + ", " 
           + StringValues.DATE_TO_STRING.getString(((File) value).lastModified());
 }};
 table.setCellRenderer(File.class, new DefaultTableRenderer(sv));
 

Note: DefaultTableCellRenderer and subclasses require a hack to play nicely with Highlighters because it has an internal "color memory" in setForeground/setBackground. The hack is applied by default which might lead to unexpected side-effects in custom renderers subclassing DTCR. See resetDefaultTableCellRendererHighlighter for details.

Rollover

As all SwingX collection views, a JXTable supports per-cell rollover which is enabled by default. If enabled, the component fires rollover events on enter/exit of a cell which by default is promoted to the renderer if it implements RolloverRenderer, that is simulates live behaviour. The rollover events can be used by client code as well, f.i. to decorate the rollover row using a Highlighter.

 JXTable table = new JXTable();
 table.addHighlighter(new ColorHighlighter(HighlightPredicate.ROLLOVER_ROW, 
      null, Color.RED);      
 

Search

As all SwingX collection views, a JXTable is searchable. A search action is registered in its ActionMap under the key "find". The default behaviour is to ask the SearchFactory to open a search component on this component. The default keybinding is retrieved from the SearchFactory, typically ctrl-f (or cmd-f for Mac). Client code can register custom actions and/or bindings as appropriate.

JXTable provides api to vend a renderer-controlled String representation of cell content. This allows the Searchable and Highlighters to use WYSIWYM (What-You-See-Is-What-You-Match), that is pattern matching against the actual string as seen by the user.

Column Configuration

JXTable's default column model is of type TableColumnModelExt which allows management of hidden columns. Furthermore, it guarantees to delegate creation and configuration of table columns to its ColumnFactory. The factory is meant as the central place to customize column configuration.

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.

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.

Keys/Actions registered with this component:

Key bindings.

Client Properties.

See Also:
JXTableHeader.SortGestureRecognizer, Serialized Form

Nested Class Summary
static class JXTable.BooleanEditor
          The default editor for Boolean types.
static class JXTable.GenericEditor
          Default editor registered for Object.
static class JXTable.NumberEditor
          Editor for Numbers.
protected static class JXTable.TableAdapter
           
 
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  CompoundHighlighter compoundHighlighter
          The CompoundHighlighter for the table.
protected  ComponentAdapter dataAdapter
          The ComponentAdapter for model data access.
protected  org.jdesktop.swingx.JXTable.CellEditorRemover editorRemover
           
protected  FilterPipeline filters
          The FilterPipeline for the table.
static String FOCUS_NEXT_COMPONENT
           
static String FOCUS_PREVIOUS_COMPONENT
           
static String HORIZONTALSCROLL_ACTION_COMMAND
          Identifier of show horizontal scroll action, used in JXTable's ActionMap.
protected  boolean isXTableRowHeightSet
          Flag to distinguish internal settings of row height from client code settings.
static String MATCH_HIGHLIGHTER
          key for client property to use SearchHighlighter as match marker.
static String PACKALL_ACTION_COMMAND
          Identifier of pack table action, used in JXTable's ActionMap .
static String PACKSELECTED_ACTION_COMMAND
          Identifier of pack selected column action, used in JXTable's ActionMap.
protected  Highlighter resetDefaultTableCellRendererHighlighter
          The Highlighter used to hack around DefaultTableCellRenderer's color memory.
protected  Searchable searchable
          property to control search behaviour.
protected  SelectionMapper selectionMapper
          The handler for mapping view/model coordinates of row selection.
static String UIPREFIX
          The prefix marker to find table related properties in the ResourceBundle.
static String USE_DTCR_COLORMEMORY_HACK
          The key for the client property deciding about whether the color memory hack for DefaultTableCellRenderer should be used.
 
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)
          Appends a Highlighter to the end of the list of used Highlighters.
protected  void adjustComponentOrientation(Component stamp)
          Adjusts the Component's orientation to this JXTable's CO if appropriate.
protected  void adminSetRowHeight(int rowHeight)
          Sets the rowHeight for all rows to the given value.
 void columnMarginChanged(ChangeEvent e)
          Invoked when a column is moved due to a margin change.
 void columnPropertyChange(PropertyChangeEvent event)
          Notifies listeners about property changes of contained columns.
 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)
          Invoked when the selection model of the TableColumnModel is changed.
protected  void configureColumnControl()
          Configures the upper trailing corner of an enclosing JScrollPane.
protected  void configureEnclosingScrollPane()
          Configures the enclosing JScrollPane.
 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  JComponent createDefaultColumnControl()
          Creates the default column control used by this table.
protected  TableColumnModel createDefaultColumnModel()
          Returns the default column model object, which is a DefaultTableColumnModel.
 void createDefaultColumnsFromModel()
          Creates, configures and adds default TableColumns for columns in this table's TableModel.
protected  void createDefaultEditors()
          Creates default cell editors for objects, numbers, and boolean values.
protected  void createDefaultRenderers()
          Creates default cell renderers for Objects, Numbers, Dates, Booleans, and Icon/Image/s.
protected  JTableHeader createDefaultTableHeader()
          Returns the default table header object, which is a JTableHeader.
protected  ChangeListener createHighlighterChangeListener()
          Creates and returns the ChangeListener observing Highlighters.
protected  TableRolloverController<JXTable> createLinkController()
          Creates and returns a RolloverController appropriate for this component.
protected  PipelineListener createPipelineListener()
          creates the listener for changes in filters.
protected  RolloverProducer createRolloverProducer()
          Creates and returns the RolloverProducer to use with this component.
protected  void doFind()
          Starts a search on this List's visible items.
 void doLayout()
          Layouts column width.
 boolean editCellAt(int row, int column, EventObject e)
          Programmatically starts editing the cell at row and column, if those indices are in the valid range, and the cell at those indices is editable.
 boolean getAutoCreateColumnsFromModel()
          Determines whether the table will create default columns from the model.
 TableCellRenderer getCellRenderer(int row, int column)
          Returns an appropriate renderer for the cell specified by this row and column.
 TableColumn getColumn(int viewColumnIndex)
          Returns the TableColumn at view position columnIndex.
 JComponent getColumnControl()
          Returns the component used as column control.
 int getColumnCount(boolean includeHidden)
          Returns the number of contained columns.
 TableColumnExt getColumnExt(int viewColumnIndex)
          Returns the TableColumnExt at view position columnIndex.
 TableColumnExt getColumnExt(Object identifier)
          Returns the first TableColumnExt with the given identifier.
 ColumnFactory getColumnFactory()
          Returns the ColumnFactory.
 int getColumnMargin()
          Returns the margin between columns.
 List<TableColumn> getColumns()
          Returns a List of visible TableColumns.
 List<TableColumn> getColumns(boolean includeHidden)
          Returns a List of contained TableColumns.
protected  ComponentAdapter getComponentAdapter()
           
protected  ComponentAdapter getComponentAdapter(int row, int column)
          Convenience to access a configured ComponentAdapter.
protected  CompoundHighlighter getCompoundHighlighter()
          Returns the CompoundHighlighter assigned to the table, null if none.
 boolean getFillsViewportHeight()
          Returns the flag which controls the scrollableTracksViewportHeight property.
protected  PipelineListener getFilterPipelineListener()
          returns the listener for changes in filters.
 FilterPipeline getFilters()
          Returns the FilterPipeline for the table.
protected  ChangeListener getHighlighterChangeListener()
          Returns the ChangeListener to use with highlighters.
 Highlighter[] getHighlighters()
          Returns the Highlighters used by this table.
protected  TableRolloverController<JXTable> getLinkController()
          Returns the RolloverController for this component.
 TableCellRenderer getNewDefaultRenderer(Class<?> columnClass)
          Returns a new instance of the default renderer for the specified class.
 Dimension getPreferredScrollableViewportSize()
          Returns the preferred size of the viewport for this table.
 int getRowCount()
          Returns the row count in the table; if filters are applied, this is the filtered row count.
protected  SizeSequenceMapper getRowModelMapper()
          Returns the mapper used synch individual rowHeights in view/model coordinates.
 boolean getScrollableTracksViewportHeight()
          Returns false to indicate that the height of the viewport does not determine the height of the table.
 boolean getScrollableTracksViewportWidth()
          Returns false if autoResizeMode is set to AUTO_RESIZE_OFF, which indicates that the width of the viewport does not determine the width of the table.
 Searchable getSearchable()
          Returns a Searchable for this component, guaranteed to be not null.
 SelectionMapper getSelectionMapper()
           
 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 given column.
 SortOrder getSortOrder(Object identifier)
          Returns the SortOrder of the given column.
 String getStringAt(int row, int column)
          Returns the string representation of the cell value at the given position.
protected  String getUIString(String key)
          Returns a potentially localized value from the UIManager.
protected  String getUIString(String key, Locale locale)
          Returns a potentially localized value from the UIManager for the given locale.
 Object getValueAt(int row, int column)
          Overridden to account for row index mapping.
 int getVisibleColumnCount()
          Returns the preferred number of columns to show in the JScrollPane.
 int getVisibleRowCount()
          Returns the preferred number of rows to show in a JScrollPane.
protected  void initializeColumnPreferredWidth(TableColumn column)
          Initialize the width related properties of the specified column.
protected  void initializeColumnWidths()
          Initialize the width related properties of all contained TableColumns, both visible and hidden.
 boolean isAutoStartEditOnKeyStroke()
          Returns the autoStartsEdit property.
 boolean isCellEditable(int row, int column)
          Returns true if the cell at row and column is editable.
 boolean isColumnControlVisible()
          Returns the column control visible property.
protected  boolean isDataChanged(TableModelEvent e)
          Convenience method to detect dataChanged table event type.
 boolean isEditable()
          Returns the editable property of the JXTable as a whole.
 boolean isFocusCycleRoot()
          Returns whether this Container is the root of a focus traversal cycle.
 boolean isHorizontalScrollEnabled()
          Returns the current setting for horizontal scrolling.
 boolean isRolloverEnabled()
          Returns a boolean indicating whether or not rollover support is enabled.
 boolean isRowHeightEnabled()
          Returns a boolean to indicate whether individual row height is enabled.
 boolean isSortable()
          Returns the table's sortable property.
protected  boolean isSortable(int columnIndex)
          Decides if the column at columnIndex can be interactively sorted.
protected  boolean isSortable(Object identifier)
          Decides if the column with identifier can be interactively sorted.
protected  boolean isStructureChanged(TableModelEvent e)
          Convenience method to detect a structureChanged table event type.
 boolean isTerminateEditOnFocusLost()
          Returns the property which determines the edit termination behaviour on focus lost.
protected  boolean isUpdate(TableModelEvent e)
          Convenience method to detect update table event type.
 void packAll()
          Resizes all columns to fit their content.
 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()
          Resizes the lead column to fit its content.
 void packTable(int margin)
          Packs all the columns to their optimal size.
 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.
 Component prepareRenderer(TableCellRenderer renderer, int row, int column)
          Returns the decorated Component used as a stamp to render the specified cell.
 void removeEditor()
          Overridden with backport from Mustang fix for #4684090, #4887999.
 void removeHighlighter(Highlighter highlighter)
          Removes the given Highlighter.
 void removeNotify()
          Calls the unconfigureEnclosingScrollPane method.
protected  void resetDefaultTableCellRendererColors(Component renderer, int row, int column)
          Method to apply a hack around DefaultTableCellRenderer "color memory" (Issue #258-swingx).
 void resetSortOrder()
          Resets sorting of all columns.
 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].
 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)
          Sets the table's auto resize mode when the table is resized.
 void setAutoStartEditOnKeyStroke(boolean autoStart)
          Sets the autoStartsEdit property.
 void setColumnControl(JComponent columnControl)
          Sets the component used as column control.
 void setColumnControlVisible(boolean visible)
          Sets the column control visible property.
 void setColumnFactory(ColumnFactory columnFactory)
          Sets the ColumnFactory to use for column creation and configuration.
 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)
          Sets the language-sensitive orientation that is to be used to order the elements or text within this component.
 void setEditable(boolean editable)
          Sets the editable property.
 void setFillsViewportHeight(boolean fillsViewportHeight)
          Sets the flag which controls the scrollableTracksViewportHeight property.
 void setFilters(FilterPipeline pipeline)
          Sets the FilterPipeline for filtering table rows, maybe null to remove all previously applied filters.
 void setGridColor(Color gridColor)
          Sets the color used to draw grid lines to gridColor and redisplays.
 void setHighlighters(Highlighter... highlighters)
          Sets the Highlighters to the table, replacing any old settings.
 void setHorizontalScrollEnabled(boolean enabled)
          Sets the enablement of enhanced horizontal scrolling.
 void setLocale(Locale locale)
          Sets the locale of this component.
 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.
 void setPreferredScrollableViewportSize(Dimension size)
          Sets the preferred size of the viewport for this table.
 void setRolloverEnabled(boolean rolloverEnabled)
          Sets the property to enable/disable rollover support.
 void setRowHeight(int rowHeight)
          Sets the height, in pixels, of all cells to rowHeight, revalidates, and repaints.
 void setRowHeight(int row, int rowHeight)
          Sets the height for row to rowHeight, revalidates, and repaints.
 void setRowHeightEnabled(boolean enabled)
          Sets enablement of individual rowHeight support.
 void setSearchable(Searchable searchable)
          Sets the Searchable for this table.
 void setSelectionBackground(Color selectionBackground)
          Sets the background color for selected cells.
 void setSelectionForeground(Color selectionForeground)
          Sets the foreground color for selected cells.
 void setSelectionModel(ListSelectionModel newModel)
          Overridden to update selectionMapper
 void setShowGrid(boolean showGrid)
          Sets whether the table draws grid lines around cells.
 void setShowGrid(boolean showHorizontalLines, boolean showVerticalLines)
          Convenience to set both grid line visibility and default margin for horizontal/vertical lines.
 void setSortable(boolean sortable)
          Sets "sortable" property indicating whether or not this table supports sortable columns.
 void setSortOrder(int columnIndex, SortOrder sortOrder)
          Sorts the table by the given column using SortOrder.
 void setSortOrder(Object identifier, SortOrder sortOrder)
          Sorts the table by the given column using the SortOrder.
 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.
 void setValueAt(Object aValue, int row, int column)
          Overridden to account for row index mapping.
 void setVisibleColumnCount(int visibleColumnCount)
          Sets the preferred number of Columns to show in a JScrollPane.
 void setVisibleRowCount(int visibleRowCount)
          Sets the preferred number of rows to show in a JScrollPane.
protected  boolean shouldSortOnChange(TableModelEvent e)
          Returns a boolean to indicate whether the table should be resorted after receiving the given event.
 void tableChanged(TableModelEvent e)
          additionally updates filtered state.
 void toggleSortOrder(int columnIndex)
          Toggles the sort order of the column at columnIndex.
 void toggleSortOrder(Object identifier)
          Toggles the sort order of the column with identifier.
 void transferFocus()
          Transfers the focus to the next component, as though this Component were the focus owner.
 void transferFocusBackward()
          Transfers the focus to the previous component, as though this Component were the focus owner.
protected  void unconfigureColumnControl()
          /** Unconfigures the upper trailing corner of an enclosing JScrollPane.
protected  void unconfigureEnclosingScrollPane()
          Unconfigures the enclosing JScrollPane.
protected  void updateColumnControlUI()
          Updates the ui of the columnControl if appropriate.
protected  void updateColumnUI(TableColumn column)
          Updates TableColumn after updateUI changes.
protected  void updateHighlighterUI()
          Updates highlighter after updateUI changes.
protected  void updateHorizontalAction()
          Synchs selected state of horizontal scrolling Action to enablement of enhanced auto-resize behaviour.
protected  void updateLocaleActionState(String key, Locale locale)
          Updates locale-dependent state of action registered with key in ActionMap.
protected  void updateLocaleState(Locale locale)
          Updates locale-dependent state to the given Locale.
protected  void updateOnFilterContentChanged()
          method called on change notification from filterpipeline.
protected  void updateRowHeightUI(boolean respectRowSetFlag)
          Auto-adjusts rowHeight to something more pleasing then the default.
 void updateUI()
          Notification from the UIManager that the L&F has changed.
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, columnMoved, convertColumnIndexToModel, convertColumnIndexToView, createDefaultDataModel, createDefaultSelectionModel, createScrollPaneForTable, editCellAt, editingCanceled, editingStopped, getAccessibleContext, getAutoResizeMode, getCellEditor, getCellEditor, getCellRect, getCellSelectionEnabled, getColumn, getColumnClass, getColumnCount, getColumnModel, getColumnName, getColumnSelectionAllowed, getDefaultEditor, getDefaultRenderer, getDragEnabled, getEditingColumn, getEditingRow, getEditorComponent, getGridColor, getIntercellSpacing, getModel, getPrintable, getRowHeight, getRowHeight, getRowMargin, getRowSelectionAllowed, getScrollableBlockIncrement, 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, removeRowSelectionInterval, resizeAndRepaint, selectAll, setAutoCreateColumnsFromModel, setCellEditor, setCellSelectionEnabled, setColumnModel, setColumnSelectionAllowed, setColumnSelectionInterval, setDefaultEditor, setDefaultRenderer, setDragEnabled, setEditingColumn, setEditingRow, setIntercellSpacing, setRowMargin, setRowSelectionAllowed, setRowSelectionInterval, setSelectionMode, setShowHorizontalLines, setShowVerticalLines, setSurrendersFocusOnKeystroke, setTableHeader, setUI, sizeColumnsToFit, sizeColumnsToFit, 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, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, 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, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface javax.swing.event.TableColumnModelListener
columnAdded, columnMoved
 

Field Detail

FOCUS_PREVIOUS_COMPONENT

public static final String FOCUS_PREVIOUS_COMPONENT
See Also:
Constant Field Values

FOCUS_NEXT_COMPONENT

public static final String FOCUS_NEXT_COMPONENT
See Also:
Constant Field Values

HORIZONTALSCROLL_ACTION_COMMAND

public static final String HORIZONTALSCROLL_ACTION_COMMAND
Identifier of show horizontal scroll action, used in JXTable's ActionMap.

See Also:
Constant Field Values

PACKALL_ACTION_COMMAND

public static final String PACKALL_ACTION_COMMAND
Identifier of pack table action, used in JXTable's ActionMap .

See Also:
Constant Field Values

PACKSELECTED_ACTION_COMMAND

public static final String PACKSELECTED_ACTION_COMMAND
Identifier of pack selected column action, used in JXTable's ActionMap.

See Also:
Constant Field Values

UIPREFIX

public static final String UIPREFIX
The prefix marker to find table 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.


compoundHighlighter

protected CompoundHighlighter compoundHighlighter
The CompoundHighlighter for the table.


USE_DTCR_COLORMEMORY_HACK

public static final String USE_DTCR_COLORMEMORY_HACK
The key for the client property deciding about whether the color memory hack for DefaultTableCellRenderer should be used.

See Also:
resetDefaultTableCellRendererHighlighter, Constant Field Values

resetDefaultTableCellRendererHighlighter

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


dataAdapter

protected ComponentAdapter dataAdapter
The ComponentAdapter for model data access.


selectionMapper

protected SelectionMapper selectionMapper
The handler for mapping view/model coordinates of row selection. Widened access to allow lazy instantiation in subclasses (#746-swingx).


isXTableRowHeightSet

protected boolean isXTableRowHeightSet
Flag to distinguish internal settings of row height 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), setRowHeight(int)

searchable

protected Searchable searchable
property to control search behaviour.


editorRemover

protected transient org.jdesktop.swingx.JXTable.CellEditorRemover editorRemover
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 column 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 accommodate.
numColumns - Count of columns to accommodate.

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

setRolloverEnabled

public void setRolloverEnabled(boolean rolloverEnabled)
Sets the property to enable/disable rollover support. If enabled, this component fires property changes on per-cell mouse rollover state, i.e. when the mouse enters/leaves a list cell.

This can be enabled to show "live" rollover behaviour, f.i. the cursor over a cell rendered by a JXHyperlink.

The default value is true.

Parameters:
rolloverEnabled - a boolean indicating whether or not the rollover functionality should be enabled.
See Also:
isRolloverEnabled(), getLinkController(), createRolloverProducer(), RolloverRenderer

isRolloverEnabled

public boolean isRolloverEnabled()
Returns a boolean indicating whether or not rollover support is enabled.

Returns:
a boolean indicating whether or not rollover support is enabled.
See Also:
setRolloverEnabled(boolean)

getLinkController

protected TableRolloverController<JXTable> getLinkController()
Returns the RolloverController for this component. Lazyly creates the controller if necessary, that is the return value is guaranteed to be not null.

PENDING JW: rename to getRolloverController

Returns:
the RolloverController for this tree, guaranteed to be not null.
See Also:
setRolloverEnabled(boolean), createLinkController(), RolloverController

createLinkController

protected TableRolloverController<JXTable> createLinkController()
Creates and returns a RolloverController appropriate for this component.

Returns:
a RolloverController appropriate for this component.
See Also:
getLinkController(), RolloverController

createRolloverProducer

protected RolloverProducer createRolloverProducer()
Creates and returns the RolloverProducer to use with this component.

Returns:
RolloverProducer to use with this component
See Also:
setRolloverEnabled(boolean)

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:
isColumnControlVisible(), 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()

unconfigureEnclosingScrollPane

protected void unconfigureEnclosingScrollPane()
Unconfigures the enclosing JScrollPane.

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

Overrides:
unconfigureEnclosingScrollPane in class JTable
See Also:
unconfigureColumnControl()

unconfigureColumnControl

protected void unconfigureColumnControl()
/** Unconfigures the upper trailing corner of an enclosing JScrollPane. Here: removes the upper trailing corner and resets.

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

configureColumnControl

protected void configureColumnControl()
Configures the upper trailing corner of an enclosing JScrollPane. Adds the ColumnControl if the columnControlVisible property is true.

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

getUIString

protected String getUIString(String key)
Returns a potentially localized value from the UIManager. The given key is prefixed by this table's UIPREFIX before doing the lookup. The lookup respects this table's current locale property. Returns the key, if no value is found.

Parameters:
key - the bare key to look up in the UIManager.
Returns:
the value mapped to UIPREFIX + key or key if no value is found.

getUIString

protected String getUIString(String key,
                             Locale locale)
Returns a potentially localized value from the UIManager for the given locale. The given key is prefixed by this table's UIPREFIX before doing the lookup. Returns the key, if no value is found.

Parameters:
key - the bare key to look up in the UIManager.
locale - the locale use for lookup
Returns:
the value mapped to UIPREFIX + key in the given locale, or key if no value is found.

setLocale

public void setLocale(Locale locale)
Sets the locale of this component. This is a bound property.

Overridden to update locale-dependent properties.

Overrides:
setLocale in class Component
Parameters:
locale - the locale to become this component's locale
See Also:
updateLocaleState(Locale)

updateLocaleState

protected void updateLocaleState(Locale locale)
Updates locale-dependent state to the given Locale. Here: updates registered column actions' locale-dependent state.

PENDING: Try better to find all column actions including custom additions? Or move to columnControl?

Parameters:
locale - the Locale to use for value lookup
See Also:
setLocale(Locale), updateLocaleActionState(String, Locale)

updateLocaleActionState

protected void updateLocaleActionState(String key,
                                       Locale locale)
Updates locale-dependent state of action registered with key in ActionMap. Does nothing if no action with key is found.

Here: updates the Action's name property.

Parameters:
key - the string for lookup in this table's ActionMap
See Also:
updateLocaleState(Locale)

packAll

public void packAll()
Resizes all columns to fit their content.

By default this method is bound to the pack all columns Action and registered in the table's ActionMap.


packSelected

public void packSelected()
Resizes the lead column to fit its content.

By default this method is bound to the pack selected column Action and registered in the table's ActionMap.


columnSelectionChanged

public void columnSelectionChanged(ListSelectionEvent e)
Invoked when the selection model of the TableColumnModel is changed.

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

Overridden to update the enabled state of the pack selected column 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)
Sets the enablement of enhanced horizontal scrolling. If enabled, it toggles an auto-resize mode which always fills the JViewport horizontally and shows the horizontal scrollbar if necessary.

The default value is false.

Note: this is not a bound property, though it follows bean naming conventions. PENDING: Probably should be... If so, could be taken by a listening Action as in the app-framework.

PENDING JW: the name is mis-leading?

Parameters:
enabled - a boolean indicating whether enhanced auto-resize mode is enabled.
See Also:
isHorizontalScrollEnabled()

isHorizontalScrollEnabled

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

Returns:
the enablement of enhanced horizontal scrolling.
See Also:
setHorizontalScrollEnabled(boolean)

setAutoResizeMode

public void setAutoResizeMode(int mode)
Sets the table's auto resize mode when the table is resized.

Overridden for internal bookkeeping related to the enhanced auto-resize behaviour.

Note: to enable/disable the enhanced auto-resize mode use exclusively setHorizontalScrollEnabled, this method can't cope with it.

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:
setHorizontalScrollEnabled(boolean)

updateHorizontalAction

protected void updateHorizontalAction()
Synchs selected state of horizontal scrolling Action to enablement of enhanced auto-resize behaviour.


getScrollableTracksViewportWidth

public boolean getScrollableTracksViewportWidth()
Returns false if autoResizeMode is set to AUTO_RESIZE_OFF, which indicates that the width of the viewport does not determine the width of the table. Otherwise returns true.

Overridden to support enhanced auto-resize behaviour 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:
setHorizontalScrollEnabled(boolean)

doLayout

public void doLayout()
Layouts column width. The exact behaviour depends on the autoResizeMode property.

Overridden to support enhanced auto-resize behaviour enabled and necessary.

Overrides:
doLayout in class JTable
See Also:
setAutoResizeMode(int), setHorizontalScrollEnabled(boolean)

columnMarginChanged

public void columnMarginChanged(ChangeEvent e)
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.

Overridden to support enhanced auto-resize behaviour enabled and necessary.

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

setFillsViewportHeight

public void setFillsViewportHeight(boolean fillsViewportHeight)
Sets the flag which controls the scrollableTracksViewportHeight property. If true the table's height will be always at least as large as the containing parent, if false the table's height will be independent of parent's height.

The default value is true.

Note: this a backport from Mustang's JTable.

Parameters:
fillsViewportHeight - boolean to indicate whether the table should always fill parent's height.
See Also:
getFillsViewportHeight(), getScrollableTracksViewportHeight()

getFillsViewportHeight

public boolean getFillsViewportHeight()
Returns the flag which controls the scrollableTracksViewportHeight property.

Returns:
true if the table's height will always be at least as large as the containing parent, false if it is independent
See Also:
setFillsViewportHeight(boolean), getScrollableTracksViewportHeight()

getScrollableTracksViewportHeight

public boolean getScrollableTracksViewportHeight()
Returns false to indicate that the height of the viewport does not determine the height of the table.

Overridden to control the tracksHeight property depending on fillsViewportHeight and relative size to containing parent.

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

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()

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()

getAutoCreateColumnsFromModel

public boolean getAutoCreateColumnsFromModel()
Determines whether the table will create default columns from the model. If true, setModel will clear any existing columns and create new columns from the new model. Also, if the event in the tableChanged notification specifies that the entire table changed, then the columns will be rebuilt. The default is true.

Overridden for documentation clarification. The property has the same meaning as super, that is if true to re-create all table columns on either setting a new TableModel or receiving a structureChanged from the existing. The most obvious visual effect is that custom column properties appear to be "lost".

JXTable does support additonal custom configuration (via a custom ColumnFactory) which can (and incorrectly was) called independently from the creation. Setting this property to false guarantees that no column configuration is applied.

Overrides:
getAutoCreateColumnsFromModel in class JTable
Returns:
the autoCreateColumnsFromModel of the table
See Also:
tableChanged(TableModelEvent), ColumnFactory

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

shouldSortOnChange

protected boolean shouldSortOnChange(TableModelEvent e)
Returns a boolean to indicate whether the table should be resorted after receiving the given event. This implementation returns true always.

NOTE: this is a quick hack to give subclasses a hook to experiment with conditional keeping the view unsorted, f.i. after edits. It's untested ... and will not receive much work because in Mustang the DefaultRowSorter has the functionality.

Parameters:
e - the event which might trigger a resort.
Returns:
a boolean indicating whether the event should trigger a re-sort, here true always.

isDataChanged

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

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 table event type.

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

Returns:
the FilterPipeline used 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(int)

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)

columnPropertyChange

public void columnPropertyChange(PropertyChangeEvent event)
Notifies listeners about property changes of contained columns. The event is the original as fired from the TableColumn. Listens to column property changes.

Specified by:
columnPropertyChange in interface TableColumnModelExtListener
Parameters:
event - a PropertyChangeEvent fired by a TableColumn contained in a TableColumnModel

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 completely by the ColumnFactory. Client code can use setColumnFactory(ColumnFactory) to plug-in a custom ColumnFactory implementing their own default column creation and behaviour.

Note: this method will probably become final (Issue #961-SwingX) so it's strongly recommended to not override now (and replace existing overrides by a custom ColumnFactory)!

Overrides:
createDefaultColumnsFromModel in class JTable
See Also:
setColumnFactory(ColumnFactory), ColumnFactory

getColumnFactory

public ColumnFactory getColumnFactory()
Returns the ColumnFactory.

Returns:
the columnFactory to use for column creation and configuration, guaranteed to not be null.
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.

Note: this method has no side-effect, that is existing columns are not re-created automatically, client code must trigger it manually.

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.

This is a bound property. The default value is 20.

PENDING: allow negative for use-all? Analogous to visColumnCount.

Parameters:
visibleRowCount - number of rows to show in a JScrollPane
Throws:
IllegalArgumentException - if given count is negative.
See Also:
getVisibleRowCount()

getVisibleColumnCount

public int getVisibleColumnCount()
Returns the preferred number of columns to show in the JScrollPane.

Returns:
the number of columns to show in the scroll pane.
See Also:
setVisibleColumnCount(int)

setVisibleColumnCount

public void setVisibleColumnCount(int visibleColumnCount)
Sets the preferred number of Columns to show in a JScrollPane. A negative number is interpreted as use-all available visible columns.

This is a bound property. The default value is -1 (effectively the same as before the introduction of this property).

Parameters:
visibleColumnCount - number of rows to show in a JScrollPane
See Also:
getVisibleColumnCount()

setPreferredScrollableViewportSize

public void setPreferredScrollableViewportSize(Dimension size)
Sets the preferred size of the viewport for this table.

If the given dimension is null, the auto-calculation of the pref scrollable size is enabled, otherwise the behaviour is the same as super. The default is auto-calc enabled on.

Overrides:
setPreferredScrollableViewportSize in class JTable
Parameters:
size - a Dimension object specifying the preferredSize of a JViewport whose view is this table
See Also:
getPreferredScrollableViewportSize()

getPreferredScrollableViewportSize

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

Overridden to support auto-calculation of pref scrollable size, dependent on the visible row/column count properties. The auto-calc is on if there's no explicit pref scrollable size set. Otherwise the fixed size is returned

The calculation of the preferred scrollable width is delegated to the ColumnFactory to allow configuration with custom strategies implemented in custom factories.

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:
setPreferredScrollableViewportSize(Dimension), ColumnFactory.getPreferredScrollableViewportWidth(JXTable)

initializeColumnWidths

protected void initializeColumnWidths()
Initialize the width related properties of all contained TableColumns, both visible and hidden.

See Also:
initializeColumnPreferredWidth(TableColumn)

initializeColumnPreferredWidth

protected void initializeColumnPreferredWidth(TableColumn column)
Initialize the width related properties of the specified column. The details are specified by the current ColumnFactory if the column is of type TableColumnExt. Otherwise nothing is changed.

TODO JW - need to cleanup getScrollablePreferred (refactor and inline)

Parameters:
column - TableColumn object representing view column
See Also:
ColumnFactory.configureColumnWidths(org.jdesktop.swingx.JXTable, org.jdesktop.swingx.table.TableColumnExt)

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()

doFind

protected void doFind()
Starts a search on this List's visible items. This implementation asks the SearchFactory to open a find widget on itself.


getSearchable

public Searchable getSearchable()
Returns a Searchable for this component, guaranteed to be not null. This implementation lazily creates a TableSearchable if necessary.

Returns:
a not-null Searchable for this component.
See Also:
setSearchable(Searchable), TableSearchable

setSearchable

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

Parameters:
searchable - the Searchable to use for this table, may be null to indicate using the table's default 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.

setHighlighters

public void setHighlighters(Highlighter... highlighters)
Sets the Highlighters to the table, replacing any old settings. None of the given Highlighters must be null.

This is a bound property.

Note: as of version #1.257 the null constraint is enforced strictly. To remove all highlighters use this method without param.

Parameters:
highlighters - zero or more not null highlighters to use for renderer decoration.
Throws:
NullPointerException - if array is null or array contains null values.
See Also:
getHighlighters(), addHighlighter(Highlighter), removeHighlighter(Highlighter)

getHighlighters

public Highlighter[] getHighlighters()
Returns the Highlighters used by this table. Maybe empty, but guarantees to be never null.

Returns:
the Highlighters used by this table, guaranteed to never null.
See Also:
setHighlighters(Highlighter[])

addHighlighter

public void addHighlighter(Highlighter highlighter)
Appends a Highlighter to the end of the list of used Highlighters. The argument must not be null.

Parameters:
highlighter - the Highlighter to add, must not be null.
Throws:
NullPointerException - if Highlighter is null.
See Also:
removeHighlighter(Highlighter), setHighlighters(Highlighter[])

removeHighlighter

public void removeHighlighter(Highlighter highlighter)
Removes the given Highlighter.

Does nothing if the Highlighter is not contained.

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

getCompoundHighlighter

protected CompoundHighlighter getCompoundHighlighter()
Returns the CompoundHighlighter assigned to the table, null if none. PENDING: open up for subclasses again?.

Returns:
the CompoundHighlighter assigned to the table.

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.

getStringAt

public String getStringAt(int row,
                          int column)
Returns the string representation of the cell value at the given position.

Parameters:
row - the row index of the cell in view coordinates
column - the column index of the cell in view coordinates.
Returns:
the string representation of the cell value as it will appear in the table.

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. Returns the default renderer for Object if super returns null.

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

Per-column highlighters contained in TableColumnExt.getHighlighters() are applied to the renderer after the table highlighters.

TODO kgs: interaction of search highlighter and column highlighters

Note: DefaultTableCellRenderer and subclasses require a hack to play nicely with Highlighters because it has an internal "color memory" in setForeground/setBackground. The hack is applied in resetDefaultTableCellRendererColors which is called after super.prepareRenderer and before applying the Highlighters. The method is called always and for all renderers.

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:
resetDefaultTableCellRendererColors(Component, int, int), Highlighter

resetDefaultTableCellRendererColors

protected void resetDefaultTableCellRendererColors(Component renderer,
                                                   int row,
                                                   int column)
Method to apply a hack around DefaultTableCellRenderer "color memory" (Issue #258-swingx). Applies the hack if the client property USE_DTCR_COLORMEMORY_HACK having the value of Boolean.TRUE, does nothing otherwise. The property is true by default.

The hack consists of applying a specialized Highlighter to force reset the color "memory" of DefaultTableCellRenderer. Note that the hack is applied always, that is even if there are no custom Highlighters.

Client code which solves the problem at the core (that is in a well-behaved DefaultTableCellRenderer) can disable the hack by removing the client property or by subclassing and override this 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:
prepareRenderer(TableCellRenderer, int, int), USE_DTCR_COLORMEMORY_HACK, ResetDTCRColorHighlighter

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.

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, must not be null.

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.

NOTE: this doesn't work with swingx renderers! Do we really need it? It had been used in JNTable which is practically obsolete. If needed, we could make all renderer support classes clonable.

Parameters:
columnClass - Class of value being rendered
Returns:
TableCellRenderer instance which renders values of the specified type
See Also:
JTable.getDefaultRenderer(Class)

createDefaultRenderers

protected void createDefaultRenderers()
Creates default cell renderers for Objects, Numbers, Dates, Booleans, and Icon/Image/s.

Overridden to install SwingX 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:
DefaultTableRenderer, ComponentProvider

createDefaultEditors

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

Overridden to hook enhanced editors (f.i. NumberEditorExt )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()

editCellAt

public boolean editCellAt(int row,
                          int column,
                          EventObject e)
Programmatically starts editing the cell at row and column, if those indices are in the valid range, and the cell at those indices is editable. To prevent the JTable from editing a particular table, column or cell value, return false from the isCellEditable method in the TableModel interface.

overridden to install a custom editor remover.

Overrides:
editCellAt in class JTable
Parameters:
row - the row to be edited
column - the column to be edited
e - event to pass into shouldSelectCell; note that as of Java 2 platform v1.2, the call to shouldSelectCell is no longer made
Returns:
false if for any reason the cell cannot be edited, or if the indices are invalid

removeEditor

public void removeEditor()
Overridden with backport from Mustang fix for #4684090, #4887999.

Overrides:
removeEditor in class JTable

removeNotify

public void removeNotify()
Calls the unconfigureEnclosingScrollPane method.

Overridden to uninstall the custom editor remover.

Overrides:
removeNotify in class JTable
See Also:
JTable.unconfigureEnclosingScrollPane()

isFocusCycleRoot

public boolean isFocusCycleRoot()
Returns whether this Container is the root of a focus traversal cycle. Once focus enters a traversal cycle, typically it cannot leave it via focus traversal unless one of the up- or down-cycle keys is pressed. Normal traversal is limited to this Container, and all of this Container's descendants that are not descendants of inferior focus cycle roots. Note that a FocusTraversalPolicy may bend these restrictions, however. For example, ContainerOrderFocusTraversalPolicy supports implicit down-cycle traversal.

Overridden to prevent spurious focus loss to outside of table while removing the editor. This is essentially a hack around core bug #6210779. PENDING: add link to wiki!

Overrides:
isFocusCycleRoot in class Container
Returns:
whether this Container is the root of a focus traversal cycle
See Also:
Container.setFocusCycleRoot(boolean), Container.setFocusTraversalPolicy(java.awt.FocusTraversalPolicy), Container.getFocusTraversalPolicy(), ContainerOrderFocusTraversalPolicy

transferFocus

public void transferFocus()
Transfers the focus to the next component, as though this Component were the focus owner.

Overridden to try to stop the edit, if appropriate. Calls super if succeeded, does not yield otherwise.

Overrides:
transferFocus in class Component
See Also:
Component.requestFocus()

transferFocusBackward

public void transferFocusBackward()
Transfers the focus to the previous component, as though this Component were the focus owner.

Overridden to try to stop the edit, if appropiate. Calls super if succeeded, does not yield otherwise.

Overrides:
transferFocusBackward in class Container
See Also:
Component.requestFocus()

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()

updateColumnControlUI

protected void updateColumnControlUI()
Updates the ui of the columnControl if appropriate.


updateColumnUI

protected void updateColumnUI(TableColumn column)
Updates TableColumn after updateUI changes. This implementation delegates to the column if it is of type UIDependent, takes over to try an update of the column's cellEditor, Cell-/HeaderRenderer otherwise.

Parameters:
column - the tableColumn to update.

updateHighlighterUI

protected void updateHighlighterUI()
Updates highlighter after updateUI changes.

See Also:
UIDependent

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

setShowGrid

public void setShowGrid(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.

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)

setShowGrid

public void setShowGrid(boolean showGrid)
Sets whether the table draws grid lines around cells. If showGrid is true it does; if it is false it doesn't. There is no getShowGrid method as this state is held in two variables -- showHorizontalLines and showVerticalLines -- each of which can be queried independently.

Behaves exactly like super.

It's overridden to warn against a frequent programming error: this method toggles only the visibility of the grid lines, it does not update the row/column margins - which may lead to visual artefacts, as f.i. not showing the lines at all or showing normal table background in selected state where the lines should have been.

Overrides:
setShowGrid in class JTable
Parameters:
showGrid - true if table view should draw grid lines
See Also:
setShowGrid(boolean, boolean)

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

setSelectionBackground

public void setSelectionBackground(Color selectionBackground)
Sets the background color for selected cells. Cell renderers can use this color to the fill selected cells.

The default value of this property is defined by the look and feel implementation.

This is a JavaBeans bound property.

Overridden because super throws NPE on null param.

Overrides:
setSelectionBackground in class JTable
Parameters:
selectionBackground - the Color to use for the background of selected cells
See Also:
JTable.getSelectionBackground(), JTable.setSelectionForeground(java.awt.Color), JComponent.setForeground(java.awt.Color), JComponent.setBackground(java.awt.Color), JComponent.setFont(java.awt.Font)

setSelectionForeground

public void setSelectionForeground(Color selectionForeground)
Sets the foreground color for selected cells. Cell renderers can use this color to render text and graphics for selected cells.

The default value of this property is defined by the look and feel implementation.

This is a JavaBeans bound property.

Overridden because super throws NPE on null param.

Overrides:
setSelectionForeground in class JTable
Parameters:
selectionForeground - the Color to use in the foreground for selected list items
See Also:
JTable.getSelectionForeground(), JTable.setSelectionBackground(java.awt.Color), JComponent.setForeground(java.awt.Color), JComponent.setBackground(java.awt.Color), JComponent.setFont(java.awt.Font)

setGridColor

public void setGridColor(Color gridColor)
Sets the color used to draw grid lines to gridColor and redisplays. The default color is look and feel dependent.

Overridden because super throws NPE on null param.

Overrides:
setGridColor in class JTable
Parameters:
gridColor - the new color of the grid lines
See Also:
JTable.getGridColor()