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:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.event.CellEditorListener, javax.swing.event.ListSelectionListener, javax.swing.event.TableColumnModelListener, javax.swing.event.TableModelListener, javax.swing.Scrollable
Direct Known Subclasses:
JXTreeTable

public class JXTable
extends javax.swing.JTable

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

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

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

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

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

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

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

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

Keys/Actions registered with this component:

Key bindings.

Client Properties.

Author:
Ramesh Gupta, Amy Fowler, Mark Davidson, Jeanette Winzenburg
See Also:
Serialized Form

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

Field Detail

EXECUTE_BUTTON_ACTIONCOMMAND

public static final java.lang.String EXECUTE_BUTTON_ACTIONCOMMAND
See Also:
Constant Field Values

HORIZONTALSCROLL_ACTION_COMMAND

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

See Also:
Constant Field Values

PACKALL_ACTION_COMMAND

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

See Also:
Constant Field Values

PACKSELECTED_ACTION_COMMAND

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

See Also:
Constant Field Values

UIPREFIX

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

See Also:
Constant Field Values

MATCH_HIGHLIGHTER

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

See Also:
Constant Field Values

filters

protected FilterPipeline filters
The FilterPipeline for the table.


highlighters

protected HighlighterPipeline highlighters
The HighlighterPipeline for the table.


dataAdapter

protected ComponentAdapter dataAdapter
The ComponentAdapter for model data access.


isXTableRowHeightSet

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


searchable

protected Searchable searchable
Constructor Detail

JXTable

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


JXTable

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

Parameters:
dm - The model to use.

JXTable

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

Parameters:
dm - The model to use.

JXTable

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

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

JXTable

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

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

JXTable

public JXTable(java.util.Vector rowData,
               java.util.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(java.lang.Object[][] rowData,
               java.lang.Object[] columnNames)
Instantiates a JXTable with data in a array or rows and column names.

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

init

protected void init()
Initializes the table for use.


setRolloverEnabled

public void setRolloverEnabled(boolean rolloverEnabled)
Property to enable/disable rollover support. This can be enabled to show "live" rollover behaviour, f.i. the cursor over LinkModel cells. Default is disabled. If using a RolloverHighlighter on the table, this should be set to true.

Parameters:
rolloverEnabled -

getLinkController

protected JXTable.LinkController getLinkController()

createLinkController

protected JXTable.LinkController createLinkController()

createRolloverProducer

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

Returns:

isRolloverEnabled

public boolean isRolloverEnabled()
Returns the rolloverEnabled property.

Returns:
true if rollover is enabled

setDefaultLinkVisitor

public void setDefaultLinkVisitor(java.awt.event.ActionListener linkVisitor)
If the default editor for LinkModel.class is of type LinkRenderer enables link visiting with the given linkVisitor. As a side-effect the rollover property is set to true.

Parameters:
linkVisitor -

configureEnclosingScrollPane

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

Overrides:
configureEnclosingScrollPane in class javax.swing.JTable

configureViewportBackground

protected void configureViewportBackground()
set's the viewports background to this.background.

PENDING: need to repeat on background changes to this!


setComponentOrientation

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

Overrides:
setComponentOrientation in class java.awt.Component

isColumnControlVisible

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

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

Returns:

getColumnControl

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

Returns:

setColumnControlVisible

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

Parameters:
showColumnControl -

packAll

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


packSelected

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


setHorizontalScrollEnabled

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

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

columnSelectionChanged

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

Specified by:
columnSelectionChanged in interface javax.swing.event.TableColumnModelListener
Overrides:
columnSelectionChanged in class javax.swing.JTable

setAutoResizeMode

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

Overrides:
setAutoResizeMode in class javax.swing.JTable

getRowCount

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

Overrides:
getRowCount in class javax.swing.JTable

isHierarchical

public boolean isHierarchical(int column)

convertRowIndexToModel

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

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

convertRowIndexToView

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

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

getValueAt

public java.lang.Object getValueAt(int row,
                                   int column)

Overrides:
getValueAt in class javax.swing.JTable

setValueAt

public void setValueAt(java.lang.Object aValue,
                       int row,
                       int column)

Overrides:
setValueAt in class javax.swing.JTable

isCellEditable

public boolean isCellEditable(int row,
                              int column)

Overrides:
isCellEditable in class javax.swing.JTable

setModel

public void setModel(javax.swing.table.TableModel newModel)

Overrides:
setModel in class javax.swing.JTable

tableChanged

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

Specified by:
tableChanged in interface javax.swing.event.TableModelListener
Overrides:
tableChanged in class javax.swing.JTable

updateViewSizeSequence

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


getFilters

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


setFilters

public void setFilters(FilterPipeline pipeline)
Sets the FilterPipeline for filtering table rows.


getFilterPipelineListener

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


createPipelineListener

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


updateOnFilterContentChanged

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


setSortable

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

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

isSortable

public boolean isSortable()
Returns true if the table is sortable.


resetSorter

protected void resetSorter()
Removes the interactive sorter. Used by headerListener.


columnRemoved

public void columnRemoved(javax.swing.event.TableColumnModelEvent e)
Specified by:
columnRemoved in interface javax.swing.event.TableColumnModelListener
Overrides:
columnRemoved in class javax.swing.JTable

setSorter

protected void setSorter(int columnIndex)
request to sort the column at columnIndex in view coordinates. if there is already an interactive sorter for this column it's sort order is reversed. Otherwise the columns sorter is used as is. Used by headerListener.


getSorter

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

Parameters:
columnIndex - the column index in view coordinates.
Returns:
the interactive sorter if matches the column or null.

removeColumns

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


getColumns

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

Returns:

getColumns

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

Parameters:
includeHidden -
Returns:

getColumnCount

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

Parameters:
includeHidden -
Returns:

setColumnSequence

public void setColumnSequence(java.lang.Object[] identifiers)
reorders the columns in the sequence given array. Logical names that do not correspond to any column in the model will be ignored. Columns with logical names not contained are added at the end.

Parameters:
columnNames - array of logical column names

getColumnExt

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

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

getColumnExt

public TableColumnExt getColumnExt(int viewColumnIndex)
Returns the TableColumnExt object for the column in the table whose column index is equal to viewColumnIndex

Parameters:
viewColumnIndex - index of the column with the object in question
Returns:
the TableColumnExt object that matches the column index
Throws:
java.lang.IllegalArgumentException - if no TableColumn has this identifier

createDefaultColumnsFromModel

public void createDefaultColumnsFromModel()
Overrides:
createDefaultColumnsFromModel in class javax.swing.JTable

createAndConfigureColumn

protected javax.swing.table.TableColumn createAndConfigureColumn(javax.swing.table.TableModel model,
                                                                 int modelColumn)

getColumnFactory

protected ColumnFactory getColumnFactory()

getColumnMargin

public int getColumnMargin()
Returns the margin between columns.

Returns:
the margin between columns

setColumnMargin

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

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

getSelectionMode

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

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

getSearchable

public Searchable getSearchable()

setSearchable

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

Parameters:
searchable -

setVisibleRowCount

public void setVisibleRowCount(int visibleRowCount)
?


getVisibleRowCount

public int getVisibleRowCount()
?


getPreferredScrollableViewportSize

public java.awt.Dimension getPreferredScrollableViewportSize()
Specified by:
getPreferredScrollableViewportSize in interface javax.swing.Scrollable
Overrides:
getPreferredScrollableViewportSize in class javax.swing.JTable

packTable

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

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

packColumn

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

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

packColumn

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

Parameters:
column - The Column index to pack in View Coordinates
margin - The margin to apply to the column
max - The maximum width the column can be resized to. -1 mean any size.

initializeColumnPreferredWidth

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

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

getComponentAdapter

protected ComponentAdapter getComponentAdapter()

getHighlighters

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


setHighlighters

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


prepareRenderer

public java.awt.Component prepareRenderer(javax.swing.table.TableCellRenderer renderer,
                                          int row,
                                          int column)
Returns the decorated Component used as a stamp to render the specified cell. Overrides superclass version to provide support for cell decorators. Adjusts component orientation (guaranteed to happen before applying Highlighters). see - https://swingx.dev.java.net/issues/show_bug.cgi?id=145

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

prepareEditor

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

Overrides:
prepareEditor in class javax.swing.JTable

adjustComponentOrientation

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

Parameters:
stamp -

getNewDefaultRenderer

public javax.swing.table.TableCellRenderer getNewDefaultRenderer(java.lang.Class columnClass)
Returns a new instance of the default renderer for the specified class. This differs from getDefaultRenderer() in that it returns a new instance each time so that the renderer may be set and customized on a particular column. PENDING: must not return null!

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

createDefaultEditors

protected void createDefaultEditors()
?

Overrides:
createDefaultEditors in class javax.swing.JTable

createDefaultRenderers

protected void createDefaultRenderers()
Creates default cell renderers for objects, numbers, doubles, dates, booleans, icons, and links. THINK: delegate to TableCellRenderers?

Overrides:
createDefaultRenderers in class javax.swing.JTable

updateUI

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

Overrides:
updateUI in class javax.swing.JTable

updateHighlighters

protected void updateHighlighters()

setRowHeight

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

Overrides:
setRowHeight in class javax.swing.JTable

setRowHeight

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

setRowHeightEnabled

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

Parameters:
enabled -

isRowHeightEnabled

public boolean isRowHeightEnabled()

getRowModelMapper

protected SizeSequenceMapper getRowModelMapper()
Returns:

adminSetRowHeight

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


rowAtPoint

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

Overrides:
rowAtPoint in class javax.swing.JTable

createDefaultTableHeader

protected javax.swing.table.JTableHeader createDefaultTableHeader()
?

Overrides:
createDefaultTableHeader in class javax.swing.JTable

createDefaultColumnModel

protected javax.swing.table.TableColumnModel createDefaultColumnModel()
?

Overrides:
createDefaultColumnModel in class javax.swing.JTable


Copyright © 2005 Sun Microsystems All Rights Reserved.