Class JXTable
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JTable
-
- 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.RowSorterListener, javax.swing.event.TableColumnModelListener, javax.swing.event.TableModelListener, javax.swing.Scrollable, TableColumnModelExtListener
- Direct Known Subclasses:
- JXTreeTable, Table, Table.RowHeader
@JavaBean public class JXTable extends javax.swing.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 (switched to core sorting). Additionally, it provides api to apply a specific sort order, to toggle the sort order of columns identified by view index or column identifier and to reset all sorts. F.i:
Sorting sequence can be configured per column by setting the TableColumnExt'stable.setSortOrder("PERSON_ID", SortOrder.DESCENDING); table.toggleSortOder(4); table.resetSortOrder();comparatorproperty. Sorting can be disabled per column - setting the TableColumnExt'ssortableor per table bysetSortable(boolean). The table takes responsibility to propagate these properties to the current sorter, if availableNote that the enhanced sorting controls are effective only if the RowSorter is of type SortController, which it is by default. Different from core JTable, the autoCreateRowSorter property is enabled by default. If on, the JXTable creates and uses a default row sorter as returned by the createDefaultRowSorter method.
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.
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:
In addition to super default per-class registration, JXTable registers a default renderer forStringValue 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));URIs which opens the default application to view the related document as supported byDesktop. Note: this action is triggered only if rolloverEnabled is true (default value) and the cell is not editable.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
resetDefaultTableCellRendererHighlighterfor details.Note: by default JXTable disables the alternate row striping provided by Nimbus, instead it does use the color provided by Nimbus to configure the UIColorHighlighter. Like in any other LAF without striping support, client code has to explicitly turn on striping by setting a Highlighter like:
Alternatively, if client code wants to rely on the LAF provided striping support, it can set a property in the UIManager ("early" in the application lifetime to prevent JXTable to disable Nimbus handling it. In this case it is recommended to not any of the ui-dependent Highlighters provided by the HighlighterFactory.table.addHighlighter(HighlighterFactory.createSimpleStriping());UIManager.put("Nimbus.keepAlternateRowColor", Boolean.TRUE);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);Location of Trigger for ComponentPopupMenu
JXTable allows access to the mouse location that triggered the showing of the componentPopupMenu. This feature allows to implement dynamic cell-context sensitive popupMenus, either in the menu actions or in a PopupMenuListener.The example below selects the cell that was clicked, event being the
PopupMenuEventreceived in aPopupMenuListener.JXTable table = (JXTable) ((JPopupMenu) e.getSource()).getInvoker(); Point trigger = table.getPopupTriggerLocation(); if (trigger != null) { int row = table.rowAtPoint(trigger); int column = table.columnAtPoint(trigger); table.setRowSelectionInterval(row, row); table.setColumnSelectionInterval(column, column); }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 usingsetHorizontalScrollEnabled(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 usingTableColumnExt.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:
- "find" - open an appropriate search widget for searching cell content. The default action registeres itself with the SearchFactory as search target.
- "print" - print the table
-
HORIZONTALSCROLL_ACTION_COMMAND- toggle the horizontal scrollbar -
PACKSELECTED_ACTION_COMMAND- resize the selected column to fit the widest cell content -
PACKALL_ACTION_COMMAND- resize all columns to fit the widest cell content in each column
Key bindings.
- "control F" - bound to actionKey "find".
Client Properties.
-
MATCH_HIGHLIGHTER- set to Boolean.TRUE to use a SearchHighlighter to mark a cell as matching.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static classJXTable.BooleanEditorThe default editor forBooleantypes.static classJXTable.GenericEditorDefault editor registered forObject.static classJXTable.NumberEditorEditor forNumbers.-
Nested classes/interfaces inherited from class javax.swing.JTable
javax.swing.JTable.DropLocation, javax.swing.JTable.PrintMode
-
-
Field Summary
Fields Modifier and Type Field and Description static java.lang.StringFOCUS_NEXT_COMPONENTstatic java.lang.StringFOCUS_PREVIOUS_COMPONENTstatic java.lang.StringHORIZONTALSCROLL_ACTION_COMMANDIdentifier of show horizontal scroll action, used in JXTable'sActionMap.static java.lang.StringMATCH_HIGHLIGHTERkey for client property to use SearchHighlighter as match marker.static java.lang.StringPACKALL_ACTION_COMMANDIdentifier of pack table action, used in JXTable'sActionMap.static java.lang.StringPACKSELECTED_ACTION_COMMANDIdentifier of pack selected column action, used in JXTable'sActionMap.static java.lang.StringUIPREFIXThe prefix marker to find table related properties in theResourceBundle.static java.lang.StringUSE_DTCR_COLORMEMORY_HACKThe 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
-
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
-
Constructor Summary
Constructors Constructor and Description 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
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidaddHighlighter(Highlighter highlighter)Appends aHighlighterto the end of the list of usedHighlighters.voidcolumnAdded(javax.swing.event.TableColumnModelEvent e)voidcolumnMarginChanged(javax.swing.event.ChangeEvent e)voidcolumnPropertyChange(java.beans.PropertyChangeEvent event)Notifies listeners about property changes of contained columns.voidcolumnSelectionChanged(javax.swing.event.ListSelectionEvent e)voidcreateDefaultColumnsFromModel()Creates, configures and adds defaultTableColumns for columns in this table'sTableModel.voiddoLayout()Layouts column width.booleaneditCellAt(int row, int column, java.util.EventObject e)booleangetAutoCreateColumnsFromModel()booleangetAutoCreateRowSorter()javax.swing.table.TableCellRenderergetCellRenderer(int row, int column)javax.swing.table.TableColumngetColumn(int viewColumnIndex)Returns theTableColumnat view positioncolumnIndex.javax.swing.table.TableColumngetColumn(java.awt.Point p)Returns the TableColumn at the given location or null if the location is outside.javax.swing.JComponentgetColumnControl()Returns the component used as column control.intgetColumnCount(boolean includeHidden)Returns the number of contained columns.TableColumnExtgetColumnExt(int viewColumnIndex)Returns theTableColumnExtat view positioncolumnIndex.TableColumnExtgetColumnExt(java.lang.Object identifier)Returns the firstTableColumnExtwith the givenidentifier.TableColumnExtgetColumnExt(java.awt.Point p)Returns the TableColumnExt at the given location or null if the location is outside or the column is not of typeTableColumnExt.ColumnFactorygetColumnFactory()Returns the ColumnFactory.intgetColumnMargin()Returns the margin between columns.java.util.List<javax.swing.table.TableColumn>getColumns()Returns aListof visibleTableColumns.java.util.List<javax.swing.table.TableColumn>getColumns(boolean includeHidden)Returns aListof containedTableColumns.Highlighter[]getHighlighters()Returns theHighlighters used by this table.java.awt.PointgetPopupLocation(java.awt.event.MouseEvent event)java.awt.PointgetPopupTriggerLocation()Returns the location of the mouseEvent that triggered the showing of the ComponentPopupMenu.java.awt.DimensiongetPreferredScrollableViewportSize()javax.swing.RowFilter<?,?>getRowFilter()Returns the filter of the sorter, if available and of type SortController.booleangetScrollableTracksViewportWidth()SearchablegetSearchable()Returns a Searchable for this component, guaranteed to be not null.intgetSelectionMode()Returns the selection mode used by this table's selection model.javax.swing.table.TableColumngetSortedColumn()Returns the primary sort column, or null if nothing sorted or no sortKey corresponds to a TableColumn currently contained in the TableColumnModel.intgetSortedColumnIndex()Returns the view column index of the primary sort column.javax.swing.SortOrdergetSortOrder(int columnIndex)Returns the SortOrder of the given column.javax.swing.SortOrdergetSortOrder(java.lang.Object identifier)Returns the SortOrder of the given column.javax.swing.SortOrder[]getSortOrderCycle()Returns the sortOrder cycle used when toggle sorting this table's columns, guaranteed to be not null.booleangetSortsOnUpdates()Returns true if a sort should happen when the underlying model is updated; otherwise, returns false.java.lang.StringgetStringAt(int row, int column)Returns the string representation of the cell value at the given position.intgetVisibleColumnCount()Returns the preferred number of columns to show in theJScrollPane.intgetVisibleRowCount()Returns the preferred number of rows to show in aJScrollPane.booleanisAutoStartEditOnKeyStroke()Returns the autoStartsEdit property.booleanisCellEditable(int row, int column)Returns true if the cell atrowandcolumnis editable.booleanisColumnControlVisible()Returns the column control visible property.booleanisEditable()Returns the editable property of theJXTableas a whole.booleanisFocusCycleRoot()booleanisHorizontalScrollEnabled()Returns the current setting for horizontal scrolling.booleanisRolloverEnabled()Returns a boolean indicating whether or not rollover support is enabled.booleanisSortable()Returns the table's sortable property.booleanisTerminateEditOnFocusLost()Returns the property which determines the edit termination behaviour on focus lost.voidpackAll()Resizes all columns to fit their content.voidpackColumn(int column, int margin)Packs an indivudal column in the table.voidpackColumn(int column, int margin, int max)Packs an indivual column in the table to less than or equal to the maximum witdth.voidpackSelected()Resizes the lead column to fit its content.voidpackTable(int margin)Packs all the columns to their optimal size.java.awt.ComponentprepareEditor(javax.swing.table.TableCellEditor editor, int row, int column)java.awt.ComponentprepareRenderer(int row, int col)Convenience method to get the rendering component for the given cell.java.awt.ComponentprepareRenderer(javax.swing.table.TableCellRenderer renderer, int row, int column)Returns the decoratedComponentused as a stamp to render the specified cell.voidremoveEditor()Overridden with backport from Mustang fix for #4684090, #4887999.voidremoveHighlighter(Highlighter highlighter)Removes the given Highlighter.voidremoveNotify()voidresetSortOrder()Resets sorting of all columns.introwAtPoint(java.awt.Point point)voidscrollCellToVisible(int row, int column)Scrolls to make the cell at row and column visible.voidscrollColumnToVisible(int column)Scrolls horizontally to make the given column visible.voidscrollRowToVisible(int row)Scrolls vertically to make the given row visible.voidsetAutoCreateRowSorter(boolean autoCreateRowSorter)voidsetAutoResizeMode(int mode)voidsetAutoStartEditOnKeyStroke(boolean autoStart)Sets the autoStartsEdit property.voidsetColumnControl(javax.swing.JComponent columnControl)Sets the component used as column control.voidsetColumnControlVisible(boolean visible)Sets the column control visible property.voidsetColumnFactory(ColumnFactory columnFactory)Sets theColumnFactoryto use for column creation and configuration.voidsetColumnMargin(int value)Sets the margin between columns.voidsetColumnModel(javax.swing.table.TableColumnModel columnModel)voidsetColumnSequence(java.lang.Object[] identifiers)Reorders the columns in the sequence given array.voidsetComponentOrientation(java.awt.ComponentOrientation o)Sets the language-sensitive orientation that is to be used to order the elements or text within this component.voidsetDefaultRenderer(java.lang.Class<?> columnClass, javax.swing.table.TableCellRenderer renderer)voidsetEditable(boolean editable)Sets the editable property.voidsetFillsViewportHeight(boolean fillsViewportHeight)voidsetGridColor(java.awt.Color gridColor)voidsetHighlighters(Highlighter... highlighters)Sets theHighlighters to the table, replacing any old settings.voidsetHorizontalScrollEnabled(boolean enabled)Sets the enablement of enhanced horizontal scrolling.voidsetLocale(java.util.Locale locale)voidsetModel(javax.swing.table.TableModel dataModel)voidsetPreferredScrollableViewportSize(java.awt.Dimension size)voidsetRolloverEnabled(boolean rolloverEnabled)Sets the property to enable/disable rollover support.<R extends javax.swing.table.TableModel>
voidsetRowFilter(javax.swing.RowFilter<? super R,? super java.lang.Integer> filter)Sets the filter to the sorter, if available and of type SortController.voidsetRowHeight(int rowHeight)voidsetRowSorter(javax.swing.RowSorter<? extends javax.swing.table.TableModel> sorter)voidsetSearchable(Searchable searchable)Sets the Searchable for this table.voidsetSelectionBackground(java.awt.Color selectionBackground)voidsetSelectionForeground(java.awt.Color selectionForeground)voidsetShowGrid(boolean showGrid)voidsetShowGrid(boolean showHorizontalLines, boolean showVerticalLines)Convenience to set both grid line visibility and default margin for horizontal/vertical lines.voidsetSortable(boolean sortable)Sets "sortable" property indicating whether or not this table supports sortable columns.voidsetSortOrder(int columnIndex, javax.swing.SortOrder sortOrder)Sorts the table by the given column using SortOrder.voidsetSortOrder(java.lang.Object identifier, javax.swing.SortOrder sortOrder)Sorts the table by the given column using the SortOrder.voidsetSortOrderCycle(javax.swing.SortOrder... cycle)Sets the sortorder cycle used when toggle sorting this table's columns.voidsetSortsOnUpdates(boolean sortsOnUpdates)If true, specifies that a sort should happen when the underlying model is updated (rowsUpdatedis invoked).voidsetTerminateEditOnFocusLost(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.voidsetValueAt(java.lang.Object aValue, int row, int column)voidsetVisibleColumnCount(int visibleColumnCount)Sets the preferred number of Columns to show in aJScrollPane.voidsetVisibleRowCount(int visibleRowCount)Sets the preferred number of rows to show in aJScrollPane.voidsorterChanged(javax.swing.event.RowSorterEvent e)Overridden to hack around core bug http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6791934voidtableChanged(javax.swing.event.TableModelEvent e)voidtoggleSortOrder(int columnIndex)Toggles the sort order of the column at columnIndex.voidtoggleSortOrder(java.lang.Object identifier)Toggles the sort order of the column with identifier.voidtransferFocus()voidtransferFocusBackward()voidupdateUI()-
Methods inherited from class javax.swing.JTable
addColumn, addColumnSelectionInterval, addNotify, addRowSelectionInterval, changeSelection, clearSelection, columnAtPoint, columnMoved, columnRemoved, convertColumnIndexToModel, convertColumnIndexToView, convertRowIndexToModel, convertRowIndexToView, createScrollPaneForTable, editCellAt, editingCanceled, editingStopped, getAccessibleContext, getAutoResizeMode, getCellEditor, getCellEditor, getCellRect, getCellSelectionEnabled, getColumn, getColumnClass, getColumnCount, getColumnModel, getColumnName, getColumnSelectionAllowed, getDefaultEditor, getDefaultRenderer, getDragEnabled, getDropLocation, getDropMode, getEditingColumn, getEditingRow, getEditorComponent, getFillsViewportHeight, getGridColor, getIntercellSpacing, getModel, getPrintable, getRowCount, getRowHeight, getRowHeight, getRowMargin, getRowSelectionAllowed, getRowSorter, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableUnitIncrement, getSelectedColumn, getSelectedColumnCount, getSelectedColumns, getSelectedRow, getSelectedRowCount, getSelectedRows, getSelectionBackground, getSelectionForeground, getSelectionModel, getShowHorizontalLines, getShowVerticalLines, getSurrendersFocusOnKeystroke, getTableHeader, getToolTipText, getUI, getUIClassID, getUpdateSelectionOnSort, getValueAt, isCellSelected, isColumnSelected, isEditing, isRowSelected, moveColumn, print, print, print, print, print, removeColumn, removeColumnSelectionInterval, removeRowSelectionInterval, selectAll, setAutoCreateColumnsFromModel, setCellEditor, setCellSelectionEnabled, setColumnSelectionAllowed, setColumnSelectionInterval, setDefaultEditor, setDragEnabled, setDropMode, setEditingColumn, setEditingRow, setIntercellSpacing, setRowHeight, setRowMargin, setRowSelectionAllowed, setRowSelectionInterval, setSelectionMode, setSelectionModel, setShowHorizontalLines, setShowVerticalLines, setSurrendersFocusOnKeystroke, setTableHeader, setUI, setUpdateSelectionOnSort, sizeColumnsToFit, sizeColumnsToFit, valueChanged
-
Methods inherited from class javax.swing.JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, 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, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
-
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, 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, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate
-
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, 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, 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, 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
-
-
-
-
Field Detail
-
FOCUS_PREVIOUS_COMPONENT
public static final java.lang.String FOCUS_PREVIOUS_COMPONENT
- See Also:
- Constant Field Values
-
FOCUS_NEXT_COMPONENT
public static final java.lang.String FOCUS_NEXT_COMPONENT
- See Also:
- Constant Field Values
-
HORIZONTALSCROLL_ACTION_COMMAND
public static final java.lang.String HORIZONTALSCROLL_ACTION_COMMAND
Identifier of show horizontal scroll action, used in JXTable'sActionMap.- See Also:
- Constant Field Values
-
PACKALL_ACTION_COMMAND
public static final java.lang.String PACKALL_ACTION_COMMAND
Identifier of pack table action, used in JXTable'sActionMap.- See Also:
- Constant Field Values
-
PACKSELECTED_ACTION_COMMAND
public static final java.lang.String PACKSELECTED_ACTION_COMMAND
Identifier of pack selected column action, used in JXTable'sActionMap.- See Also:
- Constant Field Values
-
UIPREFIX
public static final java.lang.String UIPREFIX
The prefix marker to find table related properties in theResourceBundle.- 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
-
USE_DTCR_COLORMEMORY_HACK
public static final java.lang.String USE_DTCR_COLORMEMORY_HACK
The key for the client property deciding about whether the color memory hack for DefaultTableCellRenderer should be used.
-
-
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 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(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
-
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)
-
getPopupLocation
public java.awt.Point getPopupLocation(java.awt.event.MouseEvent event)
Overridden for bookkeeping: the given event location is stored for later access.
- Overrides:
getPopupLocationin classjavax.swing.JComponent- See Also:
getPopupTriggerLocation()
-
getPopupTriggerLocation
public java.awt.Point getPopupTriggerLocation()
Returns the location of the mouseEvent that triggered the showing of the ComponentPopupMenu.- Returns:
- the location of the mouseEvent that triggered the last showing of the ComponentPopup, or null if it was triggered by keyboard.
-
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 andJXTableis contained in aJScrollPane, the table adds the column control to the trailing corner of the scroll pane.Note: if the table is not inside a
JScrollPanethe 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 javax.swing.JComponent getColumnControl()
Returns the component used as column control. Lazily creates the control to the default if it isnull.- Returns:
- component for column control, guaranteed to be != null.
- See Also:
setColumnControl(JComponent),createDefaultColumnControl()
-
setColumnControl
public void setColumnControl(javax.swing.JComponent columnControl)
Sets the component used as column control. Updates the enclosingJScrollPaneif appropriate. Passing anullparameter restores the column control to the default.The component is automatically visible only if the
columnControlVisibleproperty istrueand the table is contained in aJScrollPane.NOTE: from the table's perspective, the column control is simply a
JComponentto 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- theJComponentto use as columnControl.- See Also:
getColumnControl(),createDefaultColumnControl(),setColumnControlVisible(boolean)
-
setComponentOrientation
public void setComponentOrientation(java.awt.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:
JScrollPanecan't cope with corners when changing component orientation at runtime. This method explicitly re-configures the column control.- Overrides:
setComponentOrientationin classjava.awt.Component- Parameters:
o- the ComponentOrientation for this table.- See Also:
Component.setComponentOrientation(ComponentOrientation)
-
setLocale
public void setLocale(java.util.Locale locale)
Overridden to update locale-dependent properties.
- Overrides:
setLocalein classjava.awt.Component- 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
Actionand registered in the table'sActionMap.
-
packSelected
public void packSelected()
Resizes the lead column to fit its content.By default this method is bound to the pack selected column
Actionand registered in the table'sActionMap.
-
columnSelectionChanged
public void columnSelectionChanged(javax.swing.event.ListSelectionEvent e)
Overridden to update the enabled state of the pack selected column
Action.- Specified by:
columnSelectionChangedin interfacejavax.swing.event.TableColumnModelListener- Overrides:
columnSelectionChangedin classjavax.swing.JTable
-
setHorizontalScrollEnabled
public void setHorizontalScrollEnabled(boolean enabled)
Sets the enablement of enhanced horizontal scrolling. If enabled, it toggles an auto-resize mode which always fills theJViewporthorizontally 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)
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:
setAutoResizeModein classjavax.swing.JTable- See Also:
setHorizontalScrollEnabled(boolean)
-
getScrollableTracksViewportWidth
public boolean getScrollableTracksViewportWidth()
Overridden to support enhanced auto-resize behaviour enabled and necessary.
- Specified by:
getScrollableTracksViewportWidthin interfacejavax.swing.Scrollable- Overrides:
getScrollableTracksViewportWidthin classjavax.swing.JTable- See Also:
setHorizontalScrollEnabled(boolean)
-
doLayout
public void doLayout()
Layouts column width. The exact behaviour depends on theautoResizeModeproperty.Overridden to support enhanced auto-resize behaviour enabled and necessary.
- Overrides:
doLayoutin classjavax.swing.JTable- See Also:
setAutoResizeMode(int),setHorizontalScrollEnabled(boolean)
-
columnMarginChanged
public void columnMarginChanged(javax.swing.event.ChangeEvent e)
Overridden to support enhanced auto-resize behaviour enabled and necessary.
- Specified by:
columnMarginChangedin interfacejavax.swing.event.TableColumnModelListener- Overrides:
columnMarginChangedin classjavax.swing.JTable- See Also:
setHorizontalScrollEnabled(boolean)
-
setFillsViewportHeight
public void setFillsViewportHeight(boolean fillsViewportHeight)
Overridden for documentation reasons only: same behaviour but different default value.
The default value is
true.- Overrides:
setFillsViewportHeightin classjavax.swing.JTable
-
setValueAt
public void setValueAt(java.lang.Object aValue, int row, int column)Overridden to respect the cell's editability, that is it has no effect if
!isCellEditable(row, column).- Overrides:
setValueAtin classjavax.swing.JTable- See Also:
isCellEditable(int, int)
-
isCellEditable
public boolean isCellEditable(int row, int column)Returns true if the cell atrowandcolumnis editable. Otherwise, invokingsetValueAton the cell will have no effect.Overridden to account for row index mapping and to support a layered editability control:
- per-table:
JXTable.isEditable() - per-column:
TableColumnExt.isEditable() - per-cell: controlled by the model
TableModel.isCellEditable()
- Overrides:
isCellEditablein classjavax.swing.JTable- Parameters:
row- the row index in view coordinatescolumn- 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)
- per-table:
-
getAutoCreateColumnsFromModel
public boolean getAutoCreateColumnsFromModel()
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:
getAutoCreateColumnsFromModelin classjavax.swing.JTable- See Also:
tableChanged(TableModelEvent),ColumnFactory
-
tableChanged
public void tableChanged(javax.swing.event.TableModelEvent e)
Overridden to update internal state related to enhanced functionality and hack around core bugs.
- re-calculate intialize column width and preferred scrollable size after a structureChanged if autocreateColumnsFromModel is true.
- update string representation control after structureChanged
- core bug #6791934 logic to force revalidate if appropriate
- Specified by:
tableChangedin interfacejavax.swing.event.TableModelListener- Overrides:
tableChangedin classjavax.swing.JTable
-
sorterChanged
public void sorterChanged(javax.swing.event.RowSorterEvent e)
Overridden to hack around core bug http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6791934- Specified by:
sorterChangedin interfacejavax.swing.event.RowSorterListener- Overrides:
sorterChangedin classjavax.swing.JTable
-
setModel
public void setModel(javax.swing.table.TableModel dataModel)
Overridden to prevent super from creating RowSorter.
- Overrides:
setModelin classjavax.swing.JTable
-
setColumnModel
public void setColumnModel(javax.swing.table.TableColumnModel columnModel)
Overridden to synch sorter state from columns.
- Overrides:
setColumnModelin classjavax.swing.JTable
-
setAutoCreateRowSorter
public void setAutoCreateRowSorter(boolean autoCreateRowSorter)
Overridden to
- fix core bug: replaces sorter even if flag doesn't change.
- use xflag (need because super's RowSorter creation is hard-coded.
- Overrides:
setAutoCreateRowSorterin classjavax.swing.JTable
-
getAutoCreateRowSorter
public boolean getAutoCreateRowSorter()
Overridden to return xflag
- Overrides:
getAutoCreateRowSorterin classjavax.swing.JTable
-
setRowSorter
public void setRowSorter(javax.swing.RowSorter<? extends javax.swing.table.TableModel> sorter)
Overridden propagate sort-related properties to the sorter after calling super, if the given RowSorter is of type SortController. Does nothing additional otherwise.
- Overrides:
setRowSorterin classjavax.swing.JTable
-
setSortable
public void setSortable(boolean sortable)
Sets "sortable" property indicating whether or not this table supports sortable columns. Ifsortableistruethen sorting will be enabled on all columns whosesortableproperty istrue. Ifsortableisfalsethen sorting will be disabled for all columns, regardless of each column's individualsortingproperty. The default istrue.Note: as of post-1.0 this property is propagated to the SortController if controlsSorterProperties is true. Whether or not a change triggers a re-sort is up to either the concrete controller implementation (the default doesn't) or client code. This behaviour is different from old SwingX style sorting.
- Parameters:
sortable- boolean indicating whether or not this table supports sortable columns- See Also:
getControlsSorterProperties()
-
isSortable
public boolean isSortable()
Returns the table's sortable property.- Returns:
- true if the table is sortable.
- See Also:
setSortable(boolean)
-
setSortsOnUpdates
public void setSortsOnUpdates(boolean sortsOnUpdates)
If true, specifies that a sort should happen when the underlying model is updated (rowsUpdatedis invoked). For example, if this is true and the user edits an entry the location of that item in the view may change. This property is propagated to the SortController if controlsSorterProperties is true.The default value is true.
- Parameters:
sortsOnUpdates- whether or not to sort on update events- See Also:
getSortsOnUpdates(),getControlsSorterProperties()
-
getSortsOnUpdates
public boolean getSortsOnUpdates()
Returns true if a sort should happen when the underlying model is updated; otherwise, returns false.- Returns:
- whether or not to sort when the model is updated
-
setSortOrderCycle
public void setSortOrderCycle(javax.swing.SortOrder... cycle)
Sets the sortorder cycle used when toggle sorting this table's columns. This property is propagated to the SortController if controlsSorterProperties is true.- Parameters:
cycle- the sequence of zero or more not-null SortOrders to cycle through.- Throws:
java.lang.NullPointerException- if the array or any of its elements are null
-
getSortOrderCycle
public javax.swing.SortOrder[] getSortOrderCycle()
Returns the sortOrder cycle used when toggle sorting this table's columns, guaranteed to be not null.- Returns:
- the sort order cycle used in toggle sort, not null
-
setRowFilter
public <R extends javax.swing.table.TableModel> void setRowFilter(javax.swing.RowFilter<? super R,? super java.lang.Integer> filter)
Sets the filter to the sorter, if available and of type SortController. Does nothing otherwise.- Parameters:
filter- the filter used to determine what entries should be included
-
getRowFilter
public javax.swing.RowFilter<?,?> getRowFilter()
Returns the filter of the sorter, if available and of type SortController. Returns null otherwise.PENDING JW: generics? had to remove return type from getSortController to make this compilable, so probably wrong.
- Returns:
- the filter used in the sorter.
-
resetSortOrder
public void resetSortOrder()
Resets sorting of all columns. Delegates to the SortController if available, or does nothing if not.PENDING JW: method name - consistent in SortController and here.
-
toggleSortOrder
public void toggleSortOrder(int columnIndex)
Toggles the sort order of the column at columnIndex. Delegates to the SortController if available, or does nothing if not.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.
PRE: 0 <= columnIndex < getColumnCount()
- Parameters:
columnIndex- the columnIndex in view coordinates.
-
setSortOrder
public void setSortOrder(int columnIndex, javax.swing.SortOrder sortOrder)Sorts the table by the given column using SortOrder. Delegates to the SortController if available, or does nothing if not.PRE: 0 <= columnIndex < getColumnCount()
- Parameters:
columnIndex- the column index in view coordinates.sortOrder- the sort order to use.
-
getSortOrder
public javax.swing.SortOrder getSortOrder(int columnIndex)
Returns the SortOrder of the given column. Delegates to the SortController if available, or returns SortOrder.UNSORTED if not.- 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(java.lang.Object identifier)
Toggles the sort order of the column with identifier. Delegates to the SortController if available, or does nothing if not.The exact behaviour of a toggle is defined by the SortController's toggleSortOrder implementation. Typically a unsorted column is sorted in ascending order, a sorted column's order is reversed.
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(java.lang.Object identifier, javax.swing.SortOrder sortOrder)Sorts the table by the given column using the SortOrder. Delegates to the SortController, if available or does nothing if not.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 javax.swing.SortOrder getSortOrder(java.lang.Object identifier)
Returns the SortOrder of the given column. Delegates to the SortController if available, or returns SortOrder.UNSORTED if not.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
-
getSortedColumn
public javax.swing.table.TableColumn getSortedColumn()
Returns the primary sort column, or null if nothing sorted or no sortKey corresponds to a TableColumn currently contained in the TableColumnModel.- 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.
-
getSortedColumnIndex
public int getSortedColumnIndex()
Returns the view column index of the primary sort column.- Returns:
- the view column index of the primary sort column or -1 if nothing sorted or the primary sort column not visible.
-
columnAdded
public void columnAdded(javax.swing.event.TableColumnModelEvent e)
Overridden to propagate sort-related column properties to the SortController and to update string representation of column.
PENDING JW: check correct update on visibility change!
PENDING JW: need cleanup of string rep after column removed (if it's a real remove)
- Specified by:
columnAddedin interfacejavax.swing.event.TableColumnModelListener- Overrides:
columnAddedin classjavax.swing.JTable
-
getColumn
public javax.swing.table.TableColumn getColumn(int viewColumnIndex)
Returns theTableColumnat view positioncolumnIndex. The return value is notnull.NOTE: This delegate method is added to protect developer's from unexpected exceptions in jdk1.5+. Super does not expose the
TableColumnaccess by index which may lead to unexpectedIllegalArgumentException: 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
TableColumnobject that matches the column index - Throws:
java.lang.ArrayIndexOutOfBoundsException- if viewColumnIndex out of allowed range.- See Also:
JTable.getColumn(Object),getColumnExt(int),TableColumnModel.getColumn(int)
-
getColumns
public java.util.List<javax.swing.table.TableColumn> getColumns()
Returns aListof visibleTableColumns.- Returns:
- a
Listof visible columns. - See Also:
getColumns(boolean)
-
getColumnMargin
public int getColumnMargin()
Returns the margin between columns.Convenience to expose column model properties through
JXTableapi.- 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 throughJXTableapi.- 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 theincludeHiddenis true or false, respectively. If false, this method returns the same count asgetColumnCount(). If the columnModel is not of typeTableColumnModelExt, 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 java.util.List<javax.swing.table.TableColumn> getColumns(boolean includeHidden)
Returns aListof containedTableColumns. Includes or excludes invisible columns, depending on whether theincludeHiddenis true or false, respectively. If false, anIteratorover the List is equivalent to theEnumerationreturned bygetColumns(). If the columnModel is not of typeTableColumnModelExt, 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
Listof contained columns. - See Also:
getColumns(),TableColumnModelExt.getColumns(boolean)
-
getColumnExt
public TableColumnExt getColumnExt(java.lang.Object identifier)
Returns the firstTableColumnExtwith the givenidentifier. The return value is null if there is no contained column with identifier or if the column withidentifieris not of typeTableColumnExt. The returned column may be visible or hidden.- Parameters:
identifier- the object used as column identifier- Returns:
- first
TableColumnExtwith 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 theTableColumnExtat view positioncolumnIndex. The return value is null, if the column at positioncolumnIndexis not of typeTableColumnExt. The returned column is visible.- Parameters:
viewColumnIndex- the index of the column desired- Returns:
- the
TableColumnExtobject that matches the column index - Throws:
java.lang.ArrayIndexOutOfBoundsException- if columnIndex out of allowed range, that is if(columnIndex < 0) || (columnIndex >= getColumnCount()).- See Also:
getColumnExt(Object),getColumn(int),TableColumnModelExt.getColumnExt(int)
-
getColumn
public javax.swing.table.TableColumn getColumn(java.awt.Point p)
Returns the TableColumn at the given location or null if the location is outside.- Parameters:
point- the location to return the column for- Returns:
- the tableColumn at the location or null
- See Also:
getColumnExt(Point)
-
getColumnExt
public TableColumnExt getColumnExt(java.awt.Point p)
Returns the TableColumnExt at the given location or null if the location is outside or the column is not of typeTableColumnExt.- Parameters:
point- the location to return the column for- Returns:
- the tableColumnExt at the location or null
- See Also:
getColumn(Point),JXTableHeader.getColumnExt(Point)
-
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. 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(java.beans.PropertyChangeEvent event)
Notifies listeners about property changes of contained columns. The event is the original as fired from theTableColumn. Listens to column property changes.- Specified by:
columnPropertyChangein interfaceTableColumnModelExtListener- Parameters:
event- aPropertyChangeEventfired by aTableColumncontained in aTableColumnModel
-
createDefaultColumnsFromModel
public final void createDefaultColumnsFromModel()
Creates, configures and adds defaultTableColumns for columns in this table'sTableModel. Removes all currently containedTableColumns. The exact type and configuration of the columns is controlled completely by theColumnFactory. Client code can usesetColumnFactory(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:
createDefaultColumnsFromModelin classjavax.swing.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 theColumnFactoryto 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,nullindicates 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 Coordinatesmargin- 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 coordinatesmargin- the margin to apply to the columnmax- 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 aJScrollPane.- 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 aJScrollPane.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 aJScrollPane- Throws:
java.lang.IllegalArgumentException- if given count is negative.- See Also:
getVisibleRowCount()
-
getVisibleColumnCount
public int getVisibleColumnCount()
Returns the preferred number of columns to show in theJScrollPane.- 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 aJScrollPane. 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 aJScrollPane- See Also:
getVisibleColumnCount()
-
setPreferredScrollableViewportSize
public void setPreferredScrollableViewportSize(java.awt.Dimension size)
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:
setPreferredScrollableViewportSizein classjavax.swing.JTable- See Also:
getPreferredScrollableViewportSize()
-
getPreferredScrollableViewportSize
public java.awt.Dimension getPreferredScrollableViewportSize()
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:
getPreferredScrollableViewportSizein interfacejavax.swing.Scrollable- Overrides:
getPreferredScrollableViewportSizein classjavax.swing.JTable- See Also:
setPreferredScrollableViewportSize(Dimension),ColumnFactory.getPreferredScrollableViewportWidth(JXTable)
-
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 aJViewport.Note: this method has no precondition as it internally uses
getCellRectwhich 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 aJViewport.Note: this method has no precondition as it internally uses
getCellRectwhich 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 aJViewport.Note: this method has no precondition as it internally uses
getCellRectwhich is lenient to off-range coordinates.- Parameters:
row- the view row index of the cellcolumn- the view column index of the cell- See Also:
scrollColumnToVisible(int),scrollRowToVisible(int),JComponent.scrollRectToVisible(Rectangle)
-
getSelectionMode
public int getSelectionMode()
Returns the selection mode used by this table's selection model.PENDING JW - setter?
- Returns:
- the selection mode used by this table's selection model
- See Also:
ListSelectionModel.getSelectionMode()
-
getSearchable
public Searchable getSearchable()
Returns a 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.
-
setHighlighters
public void setHighlighters(Highlighter... highlighters)
Sets theHighlighters 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:
java.lang.NullPointerException- if array is null or array contains null values.- See Also:
getHighlighters(),addHighlighter(Highlighter),removeHighlighter(Highlighter)
-
getHighlighters
public Highlighter[] getHighlighters()
Returns theHighlighters 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 aHighlighterto the end of the list of usedHighlighters. The argument must not be null.- Parameters:
highlighter- theHighlighterto add, must not be null.- Throws:
java.lang.NullPointerException- ifHighlighteris 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...)
-
setDefaultRenderer
public void setDefaultRenderer(java.lang.Class<?> columnClass, javax.swing.table.TableCellRenderer renderer)Overridden to synchronize the string representation. If the renderer is of type StringValue a mapping it will be used as converter for the class type. If not, the mapping is reset to default.
- Overrides:
setDefaultRendererin classjavax.swing.JTable
-
getStringAt
public java.lang.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 coordinatescolumn- 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 javax.swing.table.TableCellRenderer getCellRenderer(int row, int column)Overridden to fix core bug #4614616 (NPE if
TableModel'sClassfor the column is an interface). This method guarantees to always return anot nullvalue. Returns the default renderer forObjectif super returnsnull.Note: The lookup strategy for is unchanged compared to super. Subclasses which override this with a different lookup strategy are strongly advised to implement a custom StringValueRegistry with that lookup strategy to keep the WYSIWYM in SwingX.
- Overrides:
getCellRendererin classjavax.swing.JTable
-
prepareRenderer
public java.awt.Component prepareRenderer(javax.swing.table.TableCellRenderer renderer, int row, int column)Returns the decoratedComponentused 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
resetDefaultTableCellRendererColorswhich is called after super.prepareRenderer and before applying the Highlighters. The method is called always and for all renderers.- Overrides:
prepareRendererin classjavax.swing.JTable- Parameters:
renderer- theTableCellRendererto preparerow- the row of the cell to render, where 0 is the first rowcolumn- the column of the cell to render, where 0 is the first column- Returns:
- the decorated
Componentused as a stamp to render the specified cell - See Also:
resetDefaultTableCellRendererColors(Component, int, int),Highlighter
-
prepareRenderer
public java.awt.Component prepareRenderer(int row, int col)Convenience method to get the rendering component for the given cell.- Parameters:
row- the row of the cell to render, where 0 is the first rowcolumn- the column of the cell to render, where 0 is the first column- Returns:
- the decorated
Componentused as a stamp to render the specified cell
-
prepareEditor
public java.awt.Component prepareEditor(javax.swing.table.TableCellEditor editor, int row, int column)Overridden to adjust the editor's component orientation.
- Overrides:
prepareEditorin classjavax.swing.JTable
-
isEditable
public boolean isEditable()
Returns the editable property of theJXTableas 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 byTableColumnExt.isEditableand their per-cell editability as returned by theTableModel.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 inJTable.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, java.util.EventObject e)overridden to install a custom editor remover.
- Overrides:
editCellAtin classjavax.swing.JTable
-
removeEditor
public void removeEditor()
Overridden with backport from Mustang fix for #4684090, #4887999.- Overrides:
removeEditorin classjavax.swing.JTable
-
removeNotify
public void removeNotify()
Overridden to uninstall the custom editor remover.
- Overrides:
removeNotifyin classjavax.swing.JTable
-
isFocusCycleRoot
public boolean isFocusCycleRoot()
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:
isFocusCycleRootin classjava.awt.Container
-
transferFocus
public void transferFocus()
Overridden to try to stop the edit, if appropriate. Calls super if succeeded, does not yield otherwise.
- Overrides:
transferFocusin classjava.awt.Component
-
transferFocusBackward
public void transferFocusBackward()
Overridden to try to stop the edit, if appropiate. Calls super if succeeded, does not yield otherwise.
- Overrides:
transferFocusBackwardin classjava.awt.Component
-
updateUI
public void updateUI()
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:
updateUIin classjavax.swing.JTable
-
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)
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:
setShowGridin classjavax.swing.JTable- See Also:
setShowGrid(boolean, boolean)
-
setRowHeight
public void setRowHeight(int rowHeight)
Overriden to mark the request as client-code induced.
- Overrides:
setRowHeightin classjavax.swing.JTable- See Also:
isXTableRowHeightSet
-
rowAtPoint
public int rowAtPoint(java.awt.Point point)
Overridden to work around core Bug (ID #6291631): negative y is mapped to row 0).
- Overrides:
rowAtPointin classjavax.swing.JTable
-
setSelectionBackground
public void setSelectionBackground(java.awt.Color selectionBackground)
Overridden because super throws NPE on null param.
- Overrides:
setSelectionBackgroundin classjavax.swing.JTable
-
setSelectionForeground
public void setSelectionForeground(java.awt.Color selectionForeground)
Overridden because super throws NPE on null param.
- Overrides:
setSelectionForegroundin classjavax.swing.JTable
-
setGridColor
public void setGridColor(java.awt.Color gridColor)
Overridden because super throws NPE on null param.
- Overrides:
setGridColorin classjavax.swing.JTable
-
-
DataMelt 3.0 © DataMelt by jWork.ORG