Class JXTable
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,EventListener
,Accessible
,CellEditorListener
,ListSelectionListener
,RowSorterListener
,TableColumnModelListener
,TableModelListener
,Scrollable
,TableColumnModelExtListener
- Direct Known Subclasses:
JXTreeTable
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:
table.setSortOrder("PERSON_ID", SortOrder.DESCENDING);
table.toggleSortOder(4);
table.resetSortOrder();
Sorting sequence can be configured per column by setting the TableColumnExt's
comparator
property. Sorting can be disabled per column - setting the TableColumnExt's
sortable
or per table by setSortable(boolean)
.
The table takes responsibility to propagate these
properties to the current sorter, if available Note 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:
StringValue sv = new StringValue() {
public String getString(Object value) {
if (!(value instanceof File)) return StringValues.TO_STRING.getString(value);
return StringValues.FILE_NAME.getString(value) + ", "
+ StringValues.DATE_TO_STRING.getString(((File) value).lastModified());
}};
table.setCellRenderer(File.class, new DefaultTableRenderer(sv));
In addition to super default per-class registration, JXTable registers a default
renderer for URI
s which opens the default application to view the related
document as supported by Desktop
. 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
resetDefaultTableCellRendererHighlighter
for 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:
table.addHighlighter(HighlighterFactory.createSimpleStriping());
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.
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);
Search
As all SwingX collection views, a JXTable is searchable. A search action is registered in its ActionMap under the key "find". The default behaviour is to ask the SearchFactory to open a search component on this component. The default keybinding is retrieved from the SearchFactory, typically ctrl-f (or cmd-f for Mac). Client code can register custom actions and/or bindings as appropriate.JXTable provides api to vend a renderer-controlled String representation of cell content. This allows the Searchable and Highlighters to use WYSIWYM (What-You-See-Is-What-You-Match), that is pattern matching against the actual string as seen by the user.
Column Configuration
JXTable's default column model is of type TableColumnModelExt which allows management of hidden columns. Furthermore, it guarantees to delegate creation and configuration of table columns to its ColumnFactory. The factory is meant as the central place to customize column configuration.
Columns can be hidden or shown by setting the visible property on the
TableColumnExt using TableColumnExt.setVisible(boolean)
. Columns can
also be shown or hidden from the column control popup.
The column control popup is triggered by an icon drawn to the far right of
the column headers, above the table's scrollbar (when installed in a
JScrollPane). The popup allows the user to select which columns should be
shown or hidden, as well as to pack columns and turn on horizontal scrolling.
To show or hide the column control, use the
setColumnControlVisible(boolean show)
method.
You can resize all columns, selected columns, or a single column using the
methods like packAll()
. Packing combines several other aspects of a
JXTable. If horizontal scrolling is enabled using
setHorizontalScrollEnabled(boolean)
, then the scrollpane will allow
the table to scroll right-left, and columns will be sized to their preferred
size. To control the preferred sizing of a column, you can provide a
prototype value for the column in the TableColumnExt using
TableColumnExt.setPrototypeValue(Object)
. The prototype is used as an
indicator of the preferred size of the column. This can be useful if some
data in a given column is very long, but where the resize algorithm would
normally not pick this up.
Keys/Actions registered with this component:
- "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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate class
A small class which dispatches actions.static class
The default editor forBoolean
types.(package private) class
This class tracks changes in the keyboard focus state.static class
Default editor registered forObject
.static class
Editor forNumber
s.protected static class
Nested classes/interfaces inherited from class javax.swing.JTable
JTable.AccessibleJTable, JTable.DropLocation, JTable.PrintMode
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
flag to indicate whether the rowSorter is auto-created.private Dimension
private JComponent
The component used a column control in the upper trailing corner of an enclosingJScrollPane
.private boolean
Flag to indicate if the column control is visible.private ColumnFactory
the factory to use for column creation and configuration.protected CompoundHighlighter
The CompoundHighlighter for the table.protected ComponentAdapter
The ComponentAdapter for model data access.private boolean
property to control table's editability as a whole.protected JXTable.CellEditorRemover
protected boolean
flag to indicate if a sortOrderChanged has happened between pre- and postProcessModelChange.static final String
static final String
protected boolean
flag to indicate if forced revalidate is needed.private ChangeListener
Listens for changes from the highlighters.static final String
Identifier of show horizontal scroll action, used in JXTable'sActionMap
.private boolean
flag to indicate that it's unsafe to update sortable-related sorter properties.private boolean
internal flag indicating that we are in super.doLayout().private boolean
flag to indicate enhanced auto-resize-off behaviour is on.protected boolean
Flag to distinguish internal settings of row height from client code settings.private TableRolloverController
<JXTable> RolloverController: listens to cell over events and repaints entered/exited rows.private static final Logger
static final String
key for client property to use SearchHighlighter as match marker.private int
field to store the autoResizeMode while interactively setting horizontal scrollbar to visible.static final String
Identifier of pack table action, used in JXTable'sActionMap
.static final String
Identifier of pack selected column action, used in JXTable'sActionMap
.protected Highlighter
The Highlighter used to hack around DefaultTableCellRenderer's color memory.private RolloverProducer
Mouse/Motion/Listener keeping track of mouse moved in cell coordinates.protected Searchable
property to control search behaviour.private boolean
flag to indicate if table is interactively sortable.private SortOrder[]
private boolean
flag to indicate whether model update events should trigger resorts.private StringValueRegistry
Registry of per-cell string representation.static final String
The prefix marker to find table related properties in theResourceBundle
.static final String
The key for the client property deciding about whether the color memory hack for DefaultTableCellRenderer should be used.private int
ScrollPane's original vertical scroll policy.private int
The default number of visible columns (in a ScrollPane).private int
The default number of visible rows (in a ScrollPane).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
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
accessibleContext, 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
ConstructorsConstructorDescriptionJXTable()
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.Instantiates a JXTable with data in a array or rows and column names.Instantiates a JXTable with data in a vector or rows and column names.JXTable
(TableModel dm) Instantiates a JXTable with a specific table model.JXTable
(TableModel dm, TableColumnModel cm) Instantiates a JXTable with a specific table model.JXTable
(TableModel dm, TableColumnModel cm, ListSelectionModel sm) Instantiates a JXTable with a specific table model, column model, and selection model. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addHighlighter
(Highlighter highlighter) Appends aHighlighter
to the end of the list of usedHighlighter
s.protected void
Adjusts theComponent
's orientation to thisJXTable
's CO if appropriate.protected void
adminSetRowHeight
(int rowHeight) Sets the rowHeight for all rows to the given value.void
void
void
Notifies listeners about property changes of contained columns.void
protected void
Configures the upper trailing corner of an enclosingJScrollPane
.protected void
Configures the enclosingJScrollPane
.protected void
Propagates sort-related properties from table/columns to the sorter if it is of type SortController, does nothing otherwise.private void
Creates and addsTableColumn
s for each column of the table model.private Action
Creates and returns an Action which cancels an ongoing edit correctly.protected JComponent
Creates the default column control used by this table.protected TableColumnModel
final void
Creates, configures and adds defaultTableColumn
s for columns in this table'sTableModel
.protected void
Creates default cell editors for objects, numbers, and boolean values.protected void
Creates default cell renderers forObject
s,Number
s,Date
s,Boolean
s,Icon/Image/
s andURI
s.protected RowSorter
<? extends TableModel> Creates and returns the default RowSorter.protected StringValueRegistry
Creates and returns the default registry for StringValues.protected JTableHeader
private Action
createFocusTransferAction
(boolean forward) Creates and returns an action for forward/backward focus transfer, depending on the given flag.protected ChangeListener
Creates and returns the ChangeListener observing Highlighters.private Action
Creates and returns the defaultAction
for toggling the horizontal scrollBar.protected TableRolloverController
<JXTable> Creates and returns a RolloverController appropriate for this component.private Action
Creates and returns the default Action for packing all columns.private Action
Creates and returns the defaultAction
for packing the selected column.protected RolloverProducer
Creates and returns the RolloverProducer to use with this component.protected void
doFind()
Starts a search on this List's visible items.void
doLayout()
Layouts column width.boolean
editCellAt
(int row, int column, EventObject e) boolean
boolean
getCellRenderer
(int row, int column) getColumn
(int viewColumnIndex) Returns theTableColumn
at view positioncolumnIndex
.private TableColumn
getColumnByIdentifier
(Object identifier) Returns a contained TableColumn with the given identifier.Returns the component used as column control.int
getColumnCount
(boolean includeHidden) Returns the number of contained columns.getColumnExt
(int viewColumnIndex) Returns theTableColumnExt
at view positioncolumnIndex
.getColumnExt
(Object identifier) Returns the firstTableColumnExt
with the givenidentifier
.Returns the ColumnFactory.int
Returns the margin between columns.Returns aList
of visibleTableColumn
s.getColumns
(boolean includeHidden) Returns aList
of containedTableColumn
s.protected ComponentAdapter
protected ComponentAdapter
getComponentAdapter
(int row, int column) Convenience to access a configured ComponentAdapter.protected CompoundHighlighter
Returns the CompoundHighlighter assigned to the table, null if none.protected boolean
Returns a boolean indicating whether the table configures the sorter's properties.protected JScrollPane
Returns the enclosing JScrollPane of this table, or null if not contained in a JScrollPane or not the main view of the scrollPane.protected ChangeListener
Returns theChangeListener
to use with highlighters.Returns theHighlighter
s used by this table.protected TableRolloverController
<JXTable> Returns the RolloverController for this component.private TableColumn
Returns the column which is interactively resized.RowFilter
<?, ?> Returns the filter of the sorter, if available and of type SortController.boolean
Returns a Searchable for this component, guaranteed to be not null.int
Returns the selection mode used by this table's selection model.protected SortController
<? extends TableModel> Returns the currently active SortController.Returns the primary sort column, or null if nothing sorted or no sortKey corresponds to a TableColumn currently contained in the TableColumnModel.int
Returns the view column index of the primary sort column.getSortOrder
(int columnIndex) Returns the SortOrder of the given column.getSortOrder
(Object identifier) Returns the SortOrder of the given column.Returns the sortOrder cycle used when toggle sorting this table's columns, guaranteed to be not null.boolean
Returns true if a sort should happen when the underlying model is updated; otherwise, returns false.getStringAt
(int row, int column) Returns the string representation of the cell value at the given position.protected StringValueRegistry
Returns the StringValueRegistry which defines the string representation for each cells.protected String
getUIString
(String key) Returns a potentially localized value from the UIManager.protected String
getUIString
(String key, Locale locale) Returns a potentially localized value from the UIManager for the given locale.int
Returns the preferred number of columns to show in theJScrollPane
.int
Returns the preferred number of rows to show in aJScrollPane
.private void
removes the standard editor remover and adds the custom remover.private boolean
PRE: hasRealizedParent()private boolean
protected boolean
Returns a boolean indicating whether the table has a SortController.private void
init()
Initializes the table for use.private void
Registers additional, per-instanceAction
s to the this table's ActionMap.private void
Called in init to synch the StringValueProvider with default renderers per classprivate void
Take over ctrl-tab.protected void
Initialize the width related properties of the specified column.protected void
Initialize the width related properties of all contained TableColumns, both visible and hidden.private void
Inits per column string values from TableColumnsboolean
Returns the autoStartsEdit property.boolean
isCellEditable
(int row, int column) Returns true if the cell atrow
andcolumn
is editable.boolean
Returns the column control visible property.protected boolean
Convenience method to detect dataChanged table event type.boolean
Returns the editable property of theJXTable
as a whole.private boolean
boolean
private boolean
Returns a boolean to indicate if the current focus owner is descending from this table.boolean
Returns the current setting for horizontal scrolling.boolean
Returns a boolean indicating whether or not rollover support is enabled.boolean
Returns the table's sortable property.protected boolean
Convenience method to detect a structureChanged table event type.boolean
Returns the property which determines the edit termination behaviour on focus lost.protected boolean
Convenience method to detect update table event type.void
packAll()
Resizes all columns to fit their content.void
packColumn
(int column, int margin) Packs an indivudal column in the table.void
packColumn
(int column, int margin, int max) Packs an indivual column in the table to less than or equal to the maximum witdth.void
Resizes the lead column to fit its content.void
packTable
(int margin) Packs all the columns to their optimal size.protected void
Hack around core issue 6791934: forces a revalidate if appropriate and resets internal flags.protected void
Hack around core issue 6791934: sets the sorter changed flag if appropriate.prepareEditor
(TableCellEditor editor, int row, int column) prepareRenderer
(int row, int col) Convenience method to get the rendering component for the given cell.prepareRenderer
(TableCellRenderer renderer, int row, int column) Returns the decoratedComponent
used as a stamp to render the specified cell.protected void
Hack around core issue 6791934: sets flags to force revalidate if appropriate.protected void
Sets upper corners in JScrollPane to null if same as getColumnControl().private void
removeColumnControlFromCorners
(JScrollPane scrollPane, String... corners) private void
Remove all columns, make sure to include hidden.void
Overridden with backport from Mustang fix for #4684090, #4887999.void
removeHighlighter
(Highlighter highlighter) Removes the given Highlighter.void
private void
resetCalculatedScrollableSize
(boolean isColumn) Resets the calculated scrollable size in one dimension, if appropriate.protected void
resetDefaultTableCellRendererColors
(Component renderer, int row, int column) Method to apply a hack around DefaultTableCellRenderer "color memory" (Issue #258-swingx).void
Resets sorting of all columns.int
rowAtPoint
(Point point) void
scrollCellToVisible
(int row, int column) Scrolls to make the cell at row and column visible.void
scrollColumnToVisible
(int column) Scrolls horizontally to make the given column visible.void
scrollRowToVisible
(int row) Scrolls vertically to make the given row visible.void
setAutoCreateRowSorter
(boolean autoCreateRowSorter) void
setAutoResizeMode
(int mode) void
setAutoStartEditOnKeyStroke
(boolean autoStart) Sets the autoStartsEdit property.void
setColumnControl
(JComponent columnControl) Sets the component used as column control.void
setColumnControlVisible
(boolean visible) Sets the column control visible property.void
setColumnFactory
(ColumnFactory columnFactory) Sets theColumnFactory
to use for column creation and configuration.void
setColumnMargin
(int value) Sets the margin between columns.void
setColumnModel
(TableColumnModel columnModel) void
setColumnSequence
(Object[] identifiers) Reorders the columns in the sequence given array.void
Sets the language-sensitive orientation that is to be used to order the elements or text within this component.void
setDefaultRenderer
(Class<?> columnClass, TableCellRenderer renderer) void
setEditable
(boolean editable) Sets the editable property.void
setFillsViewportHeight
(boolean fillsViewportHeight) void
setGridColor
(Color gridColor) void
setHighlighters
(Highlighter... highlighters) Sets theHighlighter
s to the table, replacing any old settings.void
setHorizontalScrollEnabled
(boolean enabled) Sets the enablement of enhanced horizontal scrolling.void
void
setModel
(TableModel dataModel) void
void
setRolloverEnabled
(boolean rolloverEnabled) Sets the property to enable/disable rollover support.<R extends TableModel>
voidsetRowFilter
(RowFilter<? super R, ? super Integer> filter) Sets the filter to the sorter, if available and of type SortController.void
setRowHeight
(int rowHeight) void
setRowSorter
(RowSorter<? extends TableModel> sorter) void
setSearchable
(Searchable searchable) Sets the Searchable for this table.void
setSelectionBackground
(Color selectionBackground) void
setSelectionForeground
(Color selectionForeground) void
setShowGrid
(boolean showGrid) void
setShowGrid
(boolean showHorizontalLines, boolean showVerticalLines) Convenience to set both grid line visibility and default margin for horizontal/vertical lines.void
setSortable
(boolean sortable) Sets "sortable" property indicating whether or not this table supports sortable columns.void
setSortOrder
(int columnIndex, SortOrder sortOrder) Sorts the table by the given column using SortOrder.void
setSortOrder
(Object identifier, SortOrder sortOrder) Sorts the table by the given column using the SortOrder.void
setSortOrderCycle
(SortOrder... cycle) Sets the sortorder cycle used when toggle sorting this table's columns.void
setSortsOnUpdates
(boolean sortsOnUpdates) If true, specifies that a sort should happen when the underlying model is updated (rowsUpdated
is invoked).void
setTerminateEditOnFocusLost
(boolean terminate) Sets the property to determine whether an ongoing edit should be terminated if the focus is moved to somewhere outside of the table.void
setValueAt
(Object aValue, int row, int column) void
setVisibleColumnCount
(int visibleColumnCount) Sets the preferred number of Columns to show in aJScrollPane
.void
setVisibleRowCount
(int visibleRowCount) Sets the preferred number of rows to show in aJScrollPane
.void
Overridden to hack around core bug http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6791934void
void
toggleSortOrder
(int columnIndex) Toggles the sort order of the column at columnIndex.void
toggleSortOrder
(Object identifier) Toggles the sort order of the column with identifier.void
void
protected void
/** Unconfigures the upper trailing corner of an enclosingJScrollPane
.protected void
Unconfigures the enclosingJScrollPane
.protected void
Updates the ui of the columnControl if appropriate.protected void
updateColumnUI
(TableColumn column) Updates TableColumn after updateUI changes.private void
updateComparatorAfterColumnChanged
(TableColumn column, Comparator<?> comparator) Synch's the SortController column comparator property to the new value, if controlsSorterProperties.private void
updateEditingAfterColumnChanged
(TableColumn column, boolean editable) Adjusts editing state after column's property change.private void
updateEditorUI
(Object maybeEditor) Tries its best toupdateUI
of the potentialTableCellEditor
.protected void
Updates highlighter afterupdateUI
changes.protected void
Synchs selected state of horizontal scrollingAction
to enablement of enhanced auto-resize behaviour.protected void
updateLocaleActionState
(String key, Locale locale) Updates locale-dependent state of action registered with key inActionMap
.protected void
updateLocaleState
(Locale locale) Updates locale-dependent state to the givenLocale
.private void
updateRendererUI
(Object maybeRenderer) Tries its best toupdateUI
of the potentialTableCellRenderer
.protected void
updateRowHeightUI
(boolean respectRowSetFlag) Auto-adjusts rowHeight to something more pleasing then the default.private void
updateSortableAfterColumnChanged
(TableColumn column, boolean sortable) Synch's the SortController column sortable property to the new value, if controlsSorterProperties.private void
updateStringValueForColumn
(TableColumn tableColumn, TableCellRenderer renderer) Updates per-column StringValue in StringValueRegistry based on given tableColumn.private void
Updates per-column class in StringValueRegistry.void
updateUI()
Methods inherited from class javax.swing.JTable
addColumn, addColumnSelectionInterval, addNotify, addRowSelectionInterval, changeSelection, clearSelection, columnAtPoint, columnMoved, columnRemoved, convertColumnIndexToModel, convertColumnIndexToView, convertRowIndexToModel, convertRowIndexToView, createDefaultDataModel, createDefaultSelectionModel, 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, initializeLocalVars, isCellSelected, isColumnSelected, isEditing, isRowSelected, moveColumn, paramString, print, print, print, print, print, processKeyBinding, removeColumn, removeColumnSelectionInterval, removeRowSelectionInterval, resizeAndRepaint, 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, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, 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, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, 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, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocusUpCycle
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface javax.swing.event.TableColumnModelListener
columnMoved, columnRemoved
-
Field Details
-
FOCUS_PREVIOUS_COMPONENT
- See Also:
-
FOCUS_NEXT_COMPONENT
- See Also:
-
LOG
-
HORIZONTALSCROLL_ACTION_COMMAND
Identifier of show horizontal scroll action, used in JXTable'sActionMap
.- See Also:
-
PACKALL_ACTION_COMMAND
Identifier of pack table action, used in JXTable'sActionMap
.- See Also:
-
PACKSELECTED_ACTION_COMMAND
Identifier of pack selected column action, used in JXTable'sActionMap
.- See Also:
-
UIPREFIX
The prefix marker to find table related properties in theResourceBundle
.- See Also:
-
MATCH_HIGHLIGHTER
key for client property to use SearchHighlighter as match marker.- See Also:
-
compoundHighlighter
The CompoundHighlighter for the table. -
USE_DTCR_COLORMEMORY_HACK
The key for the client property deciding about whether the color memory hack for DefaultTableCellRenderer should be used.- See Also:
-
resetDefaultTableCellRendererHighlighter
The Highlighter used to hack around DefaultTableCellRenderer's color memory. -
dataAdapter
The ComponentAdapter for model data access. -
highlighterChangeListener
Listens for changes from the highlighters. -
columnFactory
the factory to use for column creation and configuration. -
visibleRowCount
private int visibleRowCountThe default number of visible rows (in a ScrollPane). -
visibleColumnCount
private int visibleColumnCountThe default number of visible columns (in a ScrollPane). -
columnControlVisible
private boolean columnControlVisibleFlag to indicate if the column control is visible. -
verticalScrollPolicy
private int verticalScrollPolicyScrollPane's original vertical scroll policy. If the column control is visible the policy is set to ALWAYS. -
columnControlButton
The component used a column control in the upper trailing corner of an enclosingJScrollPane
. -
rolloverProducer
Mouse/Motion/Listener keeping track of mouse moved in cell coordinates. -
linkController
RolloverController: listens to cell over events and repaints entered/exited rows. -
oldAutoResizeMode
private int oldAutoResizeModefield to store the autoResizeMode while interactively setting horizontal scrollbar to visible. -
intelliMode
private boolean intelliModeflag to indicate enhanced auto-resize-off behaviour is on. This is set/reset in setHorizontalScrollEnabled. -
inLayout
private boolean inLayoutinternal flag indicating that we are in super.doLayout(). (used in columnMarginChanged to not update the resizingCol's prefWidth). -
isXTableRowHeightSet
protected boolean isXTableRowHeightSetFlag to distinguish internal settings of row height from client code settings. The rowHeight will be internally adjusted to font size on instantiation and in updateUI if the height has not been set explicitly by the application.- See Also:
-
searchable
property to control search behaviour. -
editable
private boolean editableproperty to control table's editability as a whole. -
calculatedPrefScrollableViewportSize
-
autoCreateRowSorter
private boolean autoCreateRowSorterflag to indicate whether the rowSorter is auto-created. -
sortable
private boolean sortableflag to indicate if table is interactively sortable. -
sortsOnUpdates
private boolean sortsOnUpdatesflag to indicate whether model update events should trigger resorts. -
ignoreAddColumn
private boolean ignoreAddColumnflag to indicate that it's unsafe to update sortable-related sorter properties. -
stringValueRegistry
Registry of per-cell string representation. -
sortOrderCycle
-
forceRevalidate
protected boolean forceRevalidateflag to indicate if forced revalidate is needed. -
filteredRowCountChanged
protected boolean filteredRowCountChangedflag to indicate if a sortOrderChanged has happened between pre- and postProcessModelChange. -
editorRemover
-
-
Constructor Details
-
JXTable
public JXTable()Instantiates a JXTable with a default table model, no data. -
JXTable
Instantiates a JXTable with a specific table model.- Parameters:
dm
- The model to use.
-
JXTable
Instantiates a JXTable with a specific table model.- Parameters:
dm
- The model to use.
-
JXTable
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
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
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 Details
-
init
private void init()Initializes the table for use. -
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
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:
-
getLinkController
Returns the RolloverController for this component. Lazyly creates the controller if necessary, that is the return value is guaranteed to be not null.PENDING JW: rename to getRolloverController
- Returns:
- the RolloverController for this tree, guaranteed to be not null.
- See Also:
-
createLinkController
Creates and returns a RolloverController appropriate for this component.- Returns:
- a RolloverController appropriate for this component.
- See Also:
-
createRolloverProducer
Creates and returns the RolloverProducer to use with this component.- Returns:
RolloverProducer
to use with this component- See Also:
-
isColumnControlVisible
public boolean isColumnControlVisible()Returns the column control visible property.- Returns:
- boolean to indicate whether the column control is visible.
- See Also:
-
setColumnControlVisible
public void setColumnControlVisible(boolean visible) Sets the column control visible property. If true andJXTable
is 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
JScrollPane
the column control is not shown even if this returns true. In this case it's the responsibility of the client code to actually show it.The default value is
false
.- Parameters:
visible
- boolean to indicate if the column control should be shown- See Also:
-
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
Sets the component used as column control. Updates the enclosingJScrollPane
if appropriate. Passing anull
parameter restores the column control to the default.The component is automatically visible only if the
columnControlVisible
property istrue
and the table is contained in aJScrollPane
.NOTE: from the table's perspective, the column control is simply a
JComponent
to add to and keep in the trailing corner of the scrollpane. (if any). It's up the concrete control to configure itself from and keep synchronized to the columns' states.- Parameters:
columnControl
- theJComponent
to use as columnControl.- See Also:
-
createDefaultColumnControl
Creates the default column control used by this table. This implementation returns aColumnControlButton
configured with defaultColumnControlIcon
.- Returns:
- the default component used as column control.
- See Also:
-
setComponentOrientation
Sets the language-sensitive orientation that is to be used to order the elements or text within this component.Overridden to work around a core bug:
JScrollPane
can't cope with corners when changing component orientation at runtime. This method explicitly re-configures the column control.- Overrides:
setComponentOrientation
in classComponent
- Parameters:
o
- the ComponentOrientation for this table.- See Also:
-
removeColumnControlFromCorners
protected void removeColumnControlFromCorners()Sets upper corners in JScrollPane to null if same as getColumnControl(). This is a hack around core not coping correctly with component orientation.- See Also:
-
removeColumnControlFromCorners
-
configureEnclosingScrollPane
protected void configureEnclosingScrollPane()Configures the enclosingJScrollPane
.Overridden to addionally configure the upper trailing corner with the column control.
- Overrides:
configureEnclosingScrollPane
in classJTable
- See Also:
-
unconfigureEnclosingScrollPane
protected void unconfigureEnclosingScrollPane()Unconfigures the enclosingJScrollPane
.Overridden to addionally unconfigure the upper trailing corner with the column control.
- Overrides:
unconfigureEnclosingScrollPane
in classJTable
- See Also:
-
unconfigureColumnControl
protected void unconfigureColumnControl()/** Unconfigures the upper trailing corner of an enclosingJScrollPane
. Here: removes the upper trailing corner and resets.- See Also:
-
configureColumnControl
protected void configureColumnControl()Configures the upper trailing corner of an enclosingJScrollPane
. Adds theColumnControl
if thecolumnControlVisible
property is true.- See Also:
-
getEnclosingScrollPane
Returns the enclosing JScrollPane of this table, or null if not contained in a JScrollPane or not the main view of the scrollPane.- Returns:
- the enclosing JScrollPane if this table is the main view or null if not.
-
initFocusBindings
private void initFocusBindings()Take over ctrl-tab. -
createFocusTransferAction
Creates and returns an action for forward/backward focus transfer, depending on the given flag.- Parameters:
forward
- a boolean indicating the direction of the required focus transfer- Returns:
- the action bound to focusTraversal.
-
initActionsAndBindings
private void initActionsAndBindings()Registers additional, per-instanceAction
s to the this table's ActionMap. Binds the search accelerator (as returned by the SearchFactory) to the find action. -
createCancelAction
Creates and returns an Action which cancels an ongoing edit correctly. Note: the correct thing to do is to call the editor's cancelEditing, the wrong thing to do is to call table removeEditor (as core JTable does...). So this is a quick hack around a core bug, reported against SwingX in #610-swingx.- Returns:
- an Action which cancels an edit.
-
createHorizontalScrollAction
Creates and returns the defaultAction
for toggling the horizontal scrollBar. -
getUIString
Returns a potentially localized value from the UIManager. The given key is prefixed by this table'sUIPREFIX
before doing the lookup. The lookup respects this table's currentlocale
property. Returns the key, if no value is found.- Parameters:
key
- the bare key to look up in the UIManager.- Returns:
- the value mapped to UIPREFIX + key or key if no value is found.
-
getUIString
Returns a potentially localized value from the UIManager for the given locale. The given key is prefixed by this table'sUIPREFIX
before doing the lookup. Returns the key, if no value is found.- Parameters:
key
- the bare key to look up in the UIManager.locale
- the locale use for lookup- Returns:
- the value mapped to UIPREFIX + key in the given locale, or key if no value is found.
-
createPackSelectedAction
Creates and returns the defaultAction
for packing the selected column. -
createPackAllAction
Creates and returns the default Action for packing all columns. -
setLocale
Overridden to update locale-dependent properties.
-
updateLocaleState
Updates locale-dependent state to the givenLocale
. Here: updates registered column actions' locale-dependent state.PENDING: Try better to find all column actions including custom additions? Or move to columnControl?
- Parameters:
locale
- the Locale to use for value lookup- See Also:
-
updateLocaleActionState
Updates locale-dependent state of action registered with key inActionMap
. Does nothing if no action with key is found.Here: updates the
Action
's name property.- Parameters:
key
- the string for lookup in this table's ActionMap- See Also:
-
packAll
public void packAll()Resizes all columns to fit their content.By default this method is bound to the pack all columns
Action
and registered in the table'sActionMap
. -
packSelected
public void packSelected()Resizes the lead column to fit its content.By default this method is bound to the pack selected column
Action
and registered in the table'sActionMap
. -
columnSelectionChanged
Overridden to update the enabled state of the pack selected column
Action
.- Specified by:
columnSelectionChanged
in interfaceTableColumnModelListener
- Overrides:
columnSelectionChanged
in classJTable
-
setHorizontalScrollEnabled
public void setHorizontalScrollEnabled(boolean enabled) Sets the enablement of enhanced horizontal scrolling. If enabled, it toggles an auto-resize mode which always fills theJViewport
horizontally and shows the horizontal scrollbar if necessary.The default value is
false
.Note: this is not a bound property, though it follows bean naming conventions. PENDING: Probably should be... If so, could be taken by a listening Action as in the app-framework.
PENDING JW: the name is mis-leading?
- Parameters:
enabled
- a boolean indicating whether enhanced auto-resize mode is enabled.- See Also:
-
isHorizontalScrollEnabled
public boolean isHorizontalScrollEnabled()Returns the current setting for horizontal scrolling.- Returns:
- the enablement of enhanced horizontal scrolling.
- See Also:
-
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:
setAutoResizeMode
in classJTable
- See Also:
-
updateHorizontalAction
protected void updateHorizontalAction()Synchs selected state of horizontal scrollingAction
to enablement of enhanced auto-resize behaviour. -
getScrollableTracksViewportWidth
public boolean getScrollableTracksViewportWidth()Overridden to support enhanced auto-resize behaviour enabled and necessary.
- Specified by:
getScrollableTracksViewportWidth
in interfaceScrollable
- Overrides:
getScrollableTracksViewportWidth
in classJTable
- See Also:
-
doLayout
public void doLayout()Layouts column width. The exact behaviour depends on theautoResizeMode
property.Overridden to support enhanced auto-resize behaviour enabled and necessary.
-
hasRealizedParent
private boolean hasRealizedParent()- Returns:
- boolean to indicate whether the table has a realized parent.
-
hasExcessWidth
private boolean hasExcessWidth()PRE: hasRealizedParent()- Returns:
- boolean to indicate whether the table has widths excessing parent's width
-
columnMarginChanged
Overridden to support enhanced auto-resize behaviour enabled and necessary.
- Specified by:
columnMarginChanged
in interfaceTableColumnModelListener
- Overrides:
columnMarginChanged
in classJTable
- See Also:
-
getResizingColumn
Returns the column which is interactively resized. The return value is null if the header is null or has no resizing column.- Returns:
- the resizing column.
-
setFillsViewportHeight
public void setFillsViewportHeight(boolean fillsViewportHeight) Overridden for documentation reasons only: same behaviour but different default value.
The default value is
true
.- Overrides:
setFillsViewportHeight
in classJTable
-
setValueAt
Overridden to respect the cell's editability, that is it has no effect if
!isCellEditable(row, column)
.- Overrides:
setValueAt
in classJTable
- See Also:
-
isCellEditable
public boolean isCellEditable(int row, int column) Returns true if the cell atrow
andcolumn
is editable. Otherwise, invokingsetValueAt
on 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:
isCellEditable
in classJTable
- Parameters:
row
- the row index in view coordinatescolumn
- the column index in view coordinates- Returns:
- true if the cell is editable
- See Also:
- 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:
getAutoCreateColumnsFromModel
in classJTable
- See Also:
-
tableChanged
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:
tableChanged
in interfaceTableModelListener
- Overrides:
tableChanged
in classJTable
-
sorterChanged
Overridden to hack around core bug http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6791934- Specified by:
sorterChanged
in interfaceRowSorterListener
- Overrides:
sorterChanged
in classJTable
-
preprocessModelChange
Hack around core issue 6791934: sets flags to force revalidate if appropriate. Called before processing the event.- Parameters:
e
- the TableModelEvent received from the model
-
postprocessModelChange
Hack around core issue 6791934: forces a revalidate if appropriate and resets internal flags. Called after processing the event.- Parameters:
e
- the TableModelEvent received from the model
-
postprocessSorterChanged
Hack around core issue 6791934: sets the sorter changed flag if appropriate. Called after processing the event.- Parameters:
e
- the sorter event received from the sorter
-
setModel
Overridden to prevent super from creating RowSorter.
-
setColumnModel
Overridden to synch sorter state from columns.
- Overrides:
setColumnModel
in classJTable
-
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:
setAutoCreateRowSorter
in classJTable
-
getAutoCreateRowSorter
public boolean getAutoCreateRowSorter()Overridden to return xflag
- Overrides:
getAutoCreateRowSorter
in classJTable
-
setRowSorter
Overridden propagate sort-related properties to the sorter after calling super, if the given RowSorter is of type SortController. Does nothing additional otherwise.
- Overrides:
setRowSorter
in classJTable
-
configureSorterProperties
protected void configureSorterProperties()Propagates sort-related properties from table/columns to the sorter if it is of type SortController, does nothing otherwise. -
createDefaultRowSorter
Creates and returns the default RowSorter. Note that this is already configured to the current TableModel - no api in the base class to set the model?PENDING JW: review method signature - better expose the need for the model by adding a parameter?
- Returns:
- the default RowSorter.
-
isDataChanged
Convenience method to detect dataChanged table event type.- Parameters:
e
- the event to examine.- Returns:
- true if the event is of type dataChanged, false else.
-
isUpdate
Convenience method to detect update table event type.- Parameters:
e
- the event to examine.- Returns:
- true if the event is of type update and not dataChanged, false else.
-
isStructureChanged
Convenience method to detect a structureChanged table event type.- Parameters:
e
- the event to examine.- Returns:
- true if the event is of type structureChanged or null, false else.
-
setSortable
public void setSortable(boolean sortable) Sets "sortable" property indicating whether or not this table supports sortable columns. Ifsortable
istrue
then sorting will be enabled on all columns whosesortable
property istrue
. Ifsortable
isfalse
then sorting will be disabled for all columns, regardless of each column's individualsorting
property. 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:
-
isSortable
public boolean isSortable()Returns the table's sortable property.- Returns:
- true if the table is sortable.
- See Also:
-
setSortsOnUpdates
public void setSortsOnUpdates(boolean sortsOnUpdates) If true, specifies that a sort should happen when the underlying model is updated (rowsUpdated
is 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
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
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:
NullPointerException
- if the array or any of its elements are null
-
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
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
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 invalid input: '<'= columnIndex invalid input: '<' getColumnCount()
- Parameters:
columnIndex
- the columnIndex in view coordinates.
-
setSortOrder
Sorts the table by the given column using SortOrder. Delegates to the SortController if available, or does nothing if not.PRE: 0 invalid input: '<'= columnIndex invalid input: '<' getColumnCount()
- Parameters:
columnIndex
- the column index in view coordinates.sortOrder
- the sort order to use.
-
getSortOrder
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
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
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
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
-
getColumnByIdentifier
Returns a contained TableColumn with the given identifier. Note that this is a hack around weird columnModel.getColumn(Object) contract in core TableColumnModel (throws exception if not found).- Parameters:
identifier
- the column identifier- Returns:
- a TableColumn with the identifier if found, or null if not found.
-
getSortController
Returns the currently active SortController. May be null, if the current RowSorter is not an instance of SortController.PENDING JW: generics - can't get the RowFilter getter signature correct with having controller typed here.
PENDING JW: swaying about hiding or not - currently the only way to make the view not configure a RowSorter of type SortController is to let this return null.
- Returns:
- the currently active
SortController
may be null
-
hasSortController
protected boolean hasSortController()Returns a boolean indicating whether the table has a SortController. If true, the call to getSortController is guaranteed to return a not-null value.- Returns:
- a boolean indicating whether the table has a SortController.
- See Also:
-
getControlsSorterProperties
protected boolean getControlsSorterProperties()Returns a boolean indicating whether the table configures the sorter's properties. If true, guaranteed that table's and the columns' sort related properties are propagated to the sorter. If false, guaranteed to not touch the sorter's configuration.This implementation returns true if the sorter is of type SortController. Note: the synchronization is unidirection from the table to the sorter. Changing the sorter under the table's feet might lead to undefined behaviour.
- Returns:
- a boolean indicating whether the table configurers the sorter's properties.
-
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
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:
columnAdded
in interfaceTableColumnModelListener
- Overrides:
columnAdded
in classJTable
-
getColumn
Returns theTableColumn
at 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
TableColumn
access 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
TableColumn
object that matches the column index - Throws:
ArrayIndexOutOfBoundsException
- if viewColumnIndex out of allowed range.- See Also:
-
getColumns
Returns aList
of visibleTableColumn
s.- Returns:
- a
List
of visible columns. - See Also:
-
getColumnMargin
public int getColumnMargin()Returns the margin between columns.Convenience to expose column model properties through
JXTable
api.- Returns:
- the margin between columns
- See Also:
-
setColumnMargin
public void setColumnMargin(int value) Sets the margin between columns. Convenience to expose column model properties throughJXTable
api.- Parameters:
value
- margin between columns; must be greater than or equal to zero.- See Also:
-
getColumnCount
public int getColumnCount(boolean includeHidden) Returns the number of contained columns. The count includes or excludes invisible columns, depending on whether theincludeHidden
is 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:
-
getColumns
Returns aList
of containedTableColumn
s. Includes or excludes invisible columns, depending on whether theincludeHidden
is true or false, respectively. If false, anIterator
over the List is equivalent to theEnumeration
returned 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
List
of contained columns. - See Also:
-
getColumnExt
Returns the firstTableColumnExt
with the givenidentifier
. The return value is null if there is no contained column with identifier or if the column withidentifier
is not of typeTableColumnExt
. The returned column may be visible or hidden.- Parameters:
identifier
- the object used as column identifier- Returns:
- first
TableColumnExt
with the given identifier or null if none is found - See Also:
-
getColumnExt
Returns theTableColumnExt
at view positioncolumnIndex
. The return value is null, if the column at positioncolumnIndex
is not of typeTableColumnExt
. The returned column is visible.- Parameters:
viewColumnIndex
- the index of the column desired- Returns:
- the
TableColumnExt
object that matches the column index - Throws:
ArrayIndexOutOfBoundsException
- if columnIndex out of allowed range, that is if(columnIndex invalid input: '<' 0) || (columnIndex >= getColumnCount())
.- See Also:
-
setColumnSequence
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:
-
columnPropertyChange
Notifies listeners about property changes of contained columns. The event is the original as fired from theTableColumn
. Listens to column property changes.- Specified by:
columnPropertyChange
in interfaceTableColumnModelExtListener
- Parameters:
event
- aPropertyChangeEvent
fired by aTableColumn
contained in aTableColumnModel
-
updateEditingAfterColumnChanged
Adjusts editing state after column's property change. Cancels ongoing editing if the sending column is the editingColumn and the column's editable changed tofalse
, otherwise does nothing.- Parameters:
column
- theTableColumn
which sent the change notifcationeditable
- the new value of the column's editable property
-
updateSortableAfterColumnChanged
Synch's the SortController column sortable property to the new value, if controlsSorterProperties. Does nothing otherwise. This method is called on sortable property change notification from the ext column model.- Parameters:
column
- theTableColumn
which sent the change notifcationsortable
- the new value of the column's sortable property
-
updateComparatorAfterColumnChanged
Synch's the SortController column comparator property to the new value, if controlsSorterProperties. Does nothing otherwise. This method is called on comparator property change notification from the ext column model.- Parameters:
column
- theTableColumn
which sent the change notifcationsortable
- the new value of the column's sortable property
-
createDefaultColumnsFromModel
public final void createDefaultColumnsFromModel()Creates, configures and adds defaultTableColumn
s for columns in this table'sTableModel
. Removes all currently containedTableColumn
s. 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:
createDefaultColumnsFromModel
in classJTable
- See Also:
-
createAndAddColumns
private void createAndAddColumns()Creates and addsTableColumn
s for each column of the table model. -
removeColumns
private void removeColumns()Remove all columns, make sure to include hidden. -
getColumnFactory
Returns the ColumnFactory.- Returns:
- the columnFactory to use for column creation and configuration, guaranteed to not be null.
- See Also:
-
setColumnFactory
Sets theColumnFactory
to use for column creation and configuration. The default value is the shared application ColumnFactory.Note: this method has no side-effect, that is existing columns are not re-created automatically, client code must trigger it manually.
- Parameters:
columnFactory
- the factory to use,null
indicates to use the shared application factory.- See Also:
-
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
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
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:
-
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
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:
IllegalArgumentException
- if given count is negative.- See Also:
-
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
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:
-
resetCalculatedScrollableSize
private void resetCalculatedScrollableSize(boolean isColumn) Resets the calculated scrollable size in one dimension, if appropriate.- Parameters:
isColumn
- flag to denote which dimension to reset, true for width, false for height
-
setPreferredScrollableViewportSize
If the given dimension is null, the auto-calculation of the pref scrollable size is enabled, otherwise the behaviour is the same as super. The default is auto-calc enabled on.
- Overrides:
setPreferredScrollableViewportSize
in classJTable
- See Also:
-
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:
getPreferredScrollableViewportSize
in interfaceScrollable
- Overrides:
getPreferredScrollableViewportSize
in classJTable
- See Also:
-
initializeColumnWidths
protected void initializeColumnWidths()Initialize the width related properties of all contained TableColumns, both visible and hidden.- PENDING: move into ColumnFactory?
- PENDING: what to do if autoCreateColumn off?
- PENDING: public? to allow manual setting of column properties which might effect their default sizing. Needed in testing - but real-world? the factory is meant to do the property setting, based on tableModel and meta-data (from where?). But leads to funny call sequence for per-table factory (new JXTable(), table.setColumnFactory(..), table.setModel(...))
- See Also:
-
initializeColumnPreferredWidth
Initialize the width related properties of the specified column. The details are specified by the currentColumnFactory
if the column is of typeTableColumnExt
. Otherwise nothing is changed.TODO JW - need to cleanup getScrollablePreferred (refactor and inline)
- Parameters:
column
- TableColumn object representing view column- See Also:
-
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
getCellRect
which is lenient to off-range coordinates.- Parameters:
row
- the view row index of the cell- See Also:
-
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
getCellRect
which is lenient to off-range coordinates.- Parameters:
column
- the view column index of the cell- See Also:
-
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
getCellRect
which is lenient to off-range coordinates.- Parameters:
row
- the view row index of the cellcolumn
- the view column index of the cell- See Also:
-
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:
-
doFind
protected void doFind()Starts a search on this List's visible items. This implementation asks the SearchFactory to open a find widget on itself. -
getSearchable
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
Sets the Searchable for this table. If null, a default searchable will be used.- Parameters:
searchable
- the Searchable to use for this table, may be null to indicate using the table's default searchable.
-
getComponentAdapter
- Returns:
- the unconfigured ComponentAdapter.
-
getComponentAdapter
Convenience to access a configured ComponentAdapter.- Parameters:
row
- the row index in view coordinates.column
- the column index in view coordinates.- Returns:
- the configured ComponentAdapter.
-
setHighlighters
Sets theHighlighter
s to the table, replacing any old settings. None of the given Highlighters must be null.This is a bound property.
Note: as of version #1.257 the null constraint is enforced strictly. To remove all highlighters use this method without param.
- Parameters:
highlighters
- zero or more not null highlighters to use for renderer decoration.- Throws:
NullPointerException
- if array is null or array contains null values.- See Also:
-
getHighlighters
Returns theHighlighter
s 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:
-
addHighlighter
Appends aHighlighter
to the end of the list of usedHighlighter
s. The argument must not be null.- Parameters:
highlighter
- theHighlighter
to add, must not be null.- Throws:
NullPointerException
- ifHighlighter
is null.- See Also:
-
removeHighlighter
Removes the given Highlighter.Does nothing if the Highlighter is not contained.
- Parameters:
highlighter
- the Highlighter to remove.- See Also:
-
getCompoundHighlighter
Returns the CompoundHighlighter assigned to the table, null if none. PENDING: open up for subclasses again?.- Returns:
- the CompoundHighlighter assigned to the table.
-
getHighlighterChangeListener
Returns theChangeListener
to use with highlighters. Lazily creates the listener.- Returns:
- the ChangeListener for observing changes of highlighters,
guaranteed to be
not-null
-
createHighlighterChangeListener
Creates and returns the ChangeListener observing Highlighters.Here: repaints the table on receiving a stateChanged.
- Returns:
- the ChangeListener defining the reaction to changes of highlighters.
-
getStringValueRegistry
Returns the StringValueRegistry which defines the string representation for each cells. This is strictly for internal use by the table, which has the responsibility to keep in synch with registered renderers.Currently exposed for testing reasons, client code is recommended to not use nor override.
- Returns:
- the current string value registry
-
createDefaultStringValueRegistry
Creates and returns the default registry for StringValues.- Returns:
- the default registry for StringValues.
-
updateStringValueRegistryColumnClasses
private void updateStringValueRegistryColumnClasses()Updates per-column class in StringValueRegistry. This is called after structureChanged. -
updateStringValueForColumn
Updates per-column StringValue in StringValueRegistry based on given tableColumn. This is called after the column's renderer property changed or after the column is added.- Parameters:
tableColumn
- the column to update fromrenderer
- the renderer potentially useful as StringValue.
-
initDefaultStringValues
private void initDefaultStringValues()Called in init to synch the StringValueProvider with default renderers per class -
initPerColumnStringValues
private void initPerColumnStringValues()Inits per column string values from TableColumns -
setDefaultRenderer
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:
setDefaultRenderer
in classJTable
-
getStringAt
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
Overridden to fix core bug #4614616 (NPE if
TableModel
'sClass
for the column is an interface). This method guarantees to always return anot null
value. Returns the default renderer forObject
if 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:
getCellRenderer
in classJTable
-
prepareRenderer
Returns the decoratedComponent
used as a stamp to render the specified cell. Overrides superclass version to provide support for cell decorators.Adjusts component orientation (guaranteed to happen before applying Highlighters).
Per-column highlighters contained in
TableColumnExt.getHighlighters()
are applied to the renderer after the table highlighters.TODO kgs: interaction of search highlighter and column highlighters
Note: DefaultTableCellRenderer and subclasses require a hack to play nicely with Highlighters because it has an internal "color memory" in setForeground/setBackground. The hack is applied in
resetDefaultTableCellRendererColors
which is called after super.prepareRenderer and before applying the Highlighters. The method is called always and for all renderers.- Overrides:
prepareRenderer
in classJTable
- Parameters:
renderer
- theTableCellRenderer
to 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
Component
used as a stamp to render the specified cell - See Also:
-
prepareRenderer
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
Component
used as a stamp to render the specified cell
-
resetDefaultTableCellRendererColors
Method to apply a hack around DefaultTableCellRenderer "color memory" (Issue #258-swingx). Applies the hack if the client propertyUSE_DTCR_COLORMEMORY_HACK
having the value ofBoolean.TRUE
, does nothing otherwise. The property is true by default.The hack consists of applying a specialized
Highlighter
to force reset the color "memory" ofDefaultTableCellRenderer
. Note that the hack is applied always, that is even if there are no custom Highlighters.Client code which solves the problem at the core (that is in a well-behaved
DefaultTableCellRenderer
) can disable the hack by removing the client property or by subclassing and override this to do nothing.- Parameters:
renderer
- theTableCellRenderer
to hackrow
- the row of the cell to rendercolumn
- the column index of the cell to render- See Also:
-
prepareEditor
Overridden to adjust the editor's component orientation.
- Overrides:
prepareEditor
in classJTable
-
adjustComponentOrientation
Adjusts theComponent
's orientation to thisJXTable
's CO if appropriate. The parameter must not benull
.This implementation synchs the CO always.
- Parameters:
stamp
- theComponent
who's CO may need to be synched, must not benull
.
-
createDefaultRenderers
protected void createDefaultRenderers()Creates default cell renderers forObject
s,Number
s,Date
s,Boolean
s,Icon/Image/
s andURI
s.Overridden to replace all super default renderers with SwingX variants and additionally register a default for
URI
types. Note: the latter registration will fail silently in headless environments or when the runtime context doesn't support Desktop.- Overrides:
createDefaultRenderers
in classJTable
- See Also:
-
createDefaultEditors
protected void createDefaultEditors()Creates default cell editors for objects, numbers, and boolean values.Overridden to hook enhanced editors (f.i.
NumberEditorExt
- Overrides:
createDefaultEditors
in classJTable
- See Also:
-
isEditable
public boolean isEditable()Returns the editable property of theJXTable
as a whole.- Returns:
- boolean to indicate if the table is editable.
- See Also:
-
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.isEditable
and 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:
-
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
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:
-
isAutoStartEditOnKeyStroke
public boolean isAutoStartEditOnKeyStroke()Returns the autoStartsEdit property.- Returns:
- boolean to indicate whether a keyStroke should try to start editing.
- See Also:
-
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:
-
editCellAt
overridden to install a custom editor remover.
- Overrides:
editCellAt
in classJTable
-
removeEditor
public void removeEditor()Overridden with backport from Mustang fix for #4684090, #4887999.- Overrides:
removeEditor
in classJTable
-
isFocusOwnerDescending
private boolean isFocusOwnerDescending()Returns a boolean to indicate if the current focus owner is descending from this table. Returns false if not editing, otherwise walks the focusOwner hierarchy, taking popups into account.- Returns:
- a boolean to indicate if the current focus owner is contained.
-
hackEditorRemover
private void hackEditorRemover()removes the standard editor remover and adds the custom remover. -
removeNotify
public void removeNotify()Overridden to uninstall the custom editor remover.
- Overrides:
removeNotify
in classJTable
-
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:
isFocusCycleRoot
in classContainer
-
transferFocus
public void transferFocus()Overridden to try to stop the edit, if appropriate. Calls super if succeeded, does not yield otherwise.
- Overrides:
transferFocus
in classComponent
-
transferFocusBackward
public void transferFocusBackward()Overridden to try to stop the edit, if appropiate. Calls super if succeeded, does not yield otherwise.
- Overrides:
transferFocusBackward
in classComponent
-
isEditingFocusCycleRoot
private boolean isEditingFocusCycleRoot()- Returns:
- a boolean to indicate whether the table needs to fake being focus cycle root.
-
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.
-
updateColumnControlUI
protected void updateColumnControlUI()Updates the ui of the columnControl if appropriate. -
updateEditorUI
Tries its best toupdateUI
of the potentialTableCellEditor
.- Parameters:
maybeEditor
- the potential editor.
-
updateRendererUI
Tries its best toupdateUI
of the potentialTableCellRenderer
.- Parameters:
maybeRenderer
- the potential renderer.
-
updateColumnUI
Updates TableColumn after updateUI changes. This implementation delegates to the column if it is of type UIDependent, takes over to try an update of the column's cellEditor, Cell-/HeaderRenderer otherwise.- Parameters:
column
- the tableColumn to update.
-
updateHighlighterUI
protected void updateHighlighterUI()Updates highlighter afterupdateUI
changes.- See Also:
-
updateRowHeightUI
protected void updateRowHeightUI(boolean respectRowSetFlag) Auto-adjusts rowHeight to something more pleasing then the default. This method is called after instantiation and after updating the UI. Does nothing if the given parameter istrue
and the rowHeight had been already set by client code. The underlying problem is that raw types can't implement UIResource.This implementation asks the UIManager for a default value (stored with key "JXTable.rowHeight"). If none is available, calculates a "reasonable" height from the table's fontMetrics, assuming that most renderers/editors will have a border with top/bottom of 1.
- Parameters:
respectRowSetFlag
- a boolean to indicate whether client-code flag should be respected.- See Also:
-
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:
-
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:
setShowGrid
in classJTable
- See Also:
-
setRowHeight
public void setRowHeight(int rowHeight) Overriden to mark the request as client-code induced.
- Overrides:
setRowHeight
in classJTable
- See Also:
-
adminSetRowHeight
protected void adminSetRowHeight(int rowHeight) Sets the rowHeight for all rows to the given value. Keeps the flagisXTableRowHeight
unchanged. This enables the distinction between setting the height for internal reasons from doing so by client code.- Parameters:
rowHeight
- new height in pixel.- See Also:
-
rowAtPoint
Overridden to work around core Bug (ID #6291631): negative y is mapped to row 0).
- Overrides:
rowAtPoint
in classJTable
-
createDefaultTableHeader
Overridden to return a
JXTableHeader
.- Overrides:
createDefaultTableHeader
in classJTable
- See Also:
-
createDefaultColumnModel
Overridden to return a
DefaultTableColumnModelExt
.- Overrides:
createDefaultColumnModel
in classJTable
- See Also:
-
setSelectionBackground
Overridden because super throws NPE on null param.
- Overrides:
setSelectionBackground
in classJTable
-
setSelectionForeground
Overridden because super throws NPE on null param.
- Overrides:
setSelectionForeground
in classJTable
-
setGridColor
Overridden because super throws NPE on null param.
- Overrides:
setGridColor
in classJTable
-