Module is.codion.swing.common.ui
Class FilterTable<R,C>
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JTable
is.codion.swing.common.ui.component.table.FilterTable<R,C>
- Type Parameters:
R
- the type representing rowsC
- the type used to identify columns
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,EventListener
,Accessible
,CellEditorListener
,ListSelectionListener
,RowSorterListener
,TableColumnModelListener
,TableModelListener
,Scrollable
A JTable implementation for
FilterTableModel
.
Note that for the table header to display you must add this table to a JScrollPane.
For instances use the builder builder(FilterTableModel, List)
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
A builder for aFilterTable
static enum
Specifies whether to center the scrolled to row and or column.static final class
The controls.static interface
Exports the table data to a String.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
Modifier and TypeFieldDescriptionstatic final PropertyValue<Boolean>
Specifies whether columns can be rearranged in tables Value type: Boolean Default value: truestatic final PropertyValue<Integer>
Specifies the default table column resize mode for tables in the application Value type: Integer (JTable.AUTO_RESIZE_*) Default value:JTable.AUTO_RESIZE_OFF
static final PropertyValue<Boolean>
Specifies whether the table resizes the row being edited to fit the editor component.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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
autoStartsEdit
(boolean autoStartsEdit) A convenience method for setting the client property 'JTable.autoStartsEdit'.static <R,
C> FilterTable.Builder<R, C> builder
(FilterTableModel<R, C> tableModel, List<FilterTableColumn<C>> columns) Instantiates a newFilterTable.Builder
using the given modelboolean
cellVisible
(int row, int column) Returns true if the given cell is visible.void
Copies the contents of the selected cell to the clipboard.void
Copies the selected table rows as a TAB delimited string, with header, to the clipboard.void
Copies the table data as a TAB delimited string, with header, to the clipboard.protected JTableHeader
TheActionEvent
propagated when this action is performed, contains the associatedMouseEvent
as source.export()
filters()
getModel()
model()
void
scrollToColumn
(C identifier) Scrolls horizontally so that the column identified by the given identifier becomes visible.void
scrollToCoordinate
(int row, int column, FilterTable.CenterOnScroll centerOnScroll) Scrolls to the given coordinate.void
Displays a dialog for selecting the column auto-resize modevoid
Shows a dialog for selecting which columns to displayvoid
setColumnModel
(TableColumnModel columnModel) void
setModel
(TableModel dataModel) void
setSelectionMode
(int selectionMode) void
setSelectionModel
(ListSelectionModel selectionModel) static <T extends Number,
C>
SummaryModel.SummaryValues<T>summaryValues
(C identifier, FilterTableModel<?, C> tableModel, Format format) Instantiates a newSummaryModel.SummaryValues
instance.void
updateUI()
Methods inherited from class javax.swing.JTable
addColumn, addColumnSelectionInterval, addNotify, addRowSelectionInterval, changeSelection, clearSelection, columnAdded, columnAtPoint, columnMarginChanged, columnMoved, columnRemoved, columnSelectionChanged, configureEnclosingScrollPane, convertColumnIndexToModel, convertColumnIndexToView, convertRowIndexToModel, convertRowIndexToView, createDefaultColumnModel, createDefaultColumnsFromModel, createDefaultDataModel, createDefaultEditors, createDefaultRenderers, createDefaultSelectionModel, createScrollPaneForTable, doLayout, editCellAt, editCellAt, editingCanceled, editingStopped, getAccessibleContext, getAutoCreateColumnsFromModel, getAutoCreateRowSorter, getAutoResizeMode, getCellEditor, getCellEditor, getCellRect, getCellRenderer, getCellSelectionEnabled, getColumn, getColumnClass, getColumnCount, getColumnName, getColumnSelectionAllowed, getDefaultEditor, getDefaultRenderer, getDragEnabled, getDropLocation, getDropMode, getEditingColumn, getEditingRow, getEditorComponent, getFillsViewportHeight, getGridColor, getIntercellSpacing, getPreferredScrollableViewportSize, getPrintable, getRowCount, getRowHeight, getRowHeight, getRowMargin, getRowSelectionAllowed, getRowSorter, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedColumn, getSelectedColumnCount, getSelectedColumns, getSelectedRow, getSelectedRowCount, getSelectedRows, getSelectionBackground, getSelectionForeground, getSelectionModel, getShowHorizontalLines, getShowVerticalLines, getSurrendersFocusOnKeystroke, getTableHeader, getToolTipText, getUI, getUIClassID, getUpdateSelectionOnSort, getValueAt, initializeLocalVars, isCellEditable, isCellSelected, isColumnSelected, isEditing, isRowSelected, moveColumn, paramString, prepareEditor, prepareRenderer, print, print, print, print, print, processKeyBinding, removeColumn, removeColumnSelectionInterval, removeEditor, removeNotify, removeRowSelectionInterval, resizeAndRepaint, rowAtPoint, selectAll, setAutoCreateColumnsFromModel, setAutoCreateRowSorter, setAutoResizeMode, setCellEditor, setCellSelectionEnabled, setColumnSelectionAllowed, setColumnSelectionInterval, setDefaultEditor, setDefaultRenderer, setDragEnabled, setDropMode, setEditingColumn, setEditingRow, setFillsViewportHeight, setGridColor, setIntercellSpacing, setPreferredScrollableViewportSize, setRowHeight, setRowHeight, setRowMargin, setRowSelectionAllowed, setRowSelectionInterval, setRowSorter, setSelectionBackground, setSelectionForeground, setShowGrid, setShowHorizontalLines, setShowVerticalLines, setSurrendersFocusOnKeystroke, setTableHeader, setUI, setUpdateSelectionOnSort, setValueAt, sizeColumnsToFit, sizeColumnsToFit, sorterChanged, tableChanged, unconfigureEnclosingScrollPane, valueChanged
Methods inherited from class javax.swing.JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, 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, 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, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
AUTO_RESIZE_MODE
Specifies the default table column resize mode for tables in the application- Value type: Integer (JTable.AUTO_RESIZE_*)
- Default value:
JTable.AUTO_RESIZE_OFF
-
ALLOW_COLUMN_REORDERING
Specifies whether columns can be rearranged in tables- Value type: Boolean
- Default value: true
-
RESIZE_ROW_TO_FIT_EDITOR
Specifies whether the table resizes the row being edited to fit the editor component. Only applicable toFilterTableCellEditor
.- Value type: Boolean
- Default value: true
-
-
Method Details
-
updateUI
public void updateUI() -
getModel
-
model
- Returns:
- the table model
-
getColumnModel
- Overrides:
getColumnModel
in classJTable
-
columnModel
- Returns:
- the column model
-
setModel
-
setColumnModel
- Overrides:
setColumnModel
in classJTable
-
setSelectionModel
- Overrides:
setSelectionModel
in classJTable
-
filters
- Returns:
- the filter
TableConditionPanel
-
searchModel
- Returns:
- the search model
-
summaryModel
- Returns:
- the summary model
-
searchField
- Returns:
- the search field
-
doubleClickAction
TheActionEvent
propagated when this action is performed, contains the associatedMouseEvent
as source.public void actionPerformed(ActionEvent event) { MouseEvent mouseEvent = (MouseEvent) event.getSource(); Point location = mouseEvent.getLocationOnScreen(); // ... }
- Returns:
- the
Value
controlling the action to perform when a double click is performed on the table
-
sortingEnabled
- Returns:
- the
State
controlling whether sorting via the table header is enabled
-
scrollToSelectedItem
- Returns:
- the
State
controlling whether the JTable instance scrolls automatically to the coordinate of the item selected in the underlying table model
-
centerOnScroll
- Returns:
- the
Value
controlling the scrolling behaviour when scrolling to the selected row/column
-
setSelectionMode
public void setSelectionMode(int selectionMode) - Overrides:
setSelectionMode
in classJTable
-
selectColumns
public void selectColumns()Shows a dialog for selecting which columns to display -
selectAutoResizeMode
public void selectAutoResizeMode()Displays a dialog for selecting the column auto-resize mode -
cellVisible
public boolean cellVisible(int row, int column) Returns true if the given cell is visible.- Parameters:
row
- the rowcolumn
- the column- Returns:
- true if this table is contained in a scrollpanel and the cell with the given coordinates is visible.
-
scrollToColumn
Scrolls horizontally so that the column identified by the given identifier becomes visible. Has no effect if this table is not contained in a scrollpanel.- Parameters:
identifier
- the column identifier
-
scrollToCoordinate
Scrolls to the given coordinate. Has no effect if this table is not contained in a scrollpanel.- Parameters:
row
- the rowcolumn
- the columncenterOnScroll
- specifies whether to center the selected row and or column
-
copySelectedCell
public void copySelectedCell()Copies the contents of the selected cell to the clipboard. -
copyToClipboard
public void copyToClipboard()Copies the table data as a TAB delimited string, with header, to the clipboard. If the selection is empty, all rows are included, otherwise only selected ones. -
copySelectedToClipboard
public void copySelectedToClipboard()Copies the selected table rows as a TAB delimited string, with header, to the clipboard. -
export
- Returns:
- a
FilterTable.Export
instance for exporting the table model data
-
createSelectColumnsControl
- Returns:
- a control for showing the column selection dialog
-
createToggleColumnsControls
- Returns:
- Controls containing
ToggleControl
s for showing/hiding columns.
-
createResetColumnsControl
- Returns:
- a Control for resetting the columns to their original location and visibility
-
createSelectAutoResizeModeControl
- Returns:
- a Control for selecting the auto-resize mode
-
createToggleAutoResizeModeControls
- Returns:
- Controls containing
ToggleControl
s for choosing the auto resize mode.
-
createSingleSelectionModeControl
- Returns:
- a ToggleControl for toggling the table selection mode (single or multiple)
-
createCopyCellControl
- Returns:
- a Control for copying the contents of the selected cell
-
autoStartsEdit
public void autoStartsEdit(boolean autoStartsEdit) A convenience method for setting the client property 'JTable.autoStartsEdit'.- Parameters:
autoStartsEdit
- the value
-
doubleClick
- Returns:
- an observer notified each time the table is double-clicked
-
summaryValues
public static <T extends Number,C> SummaryModel.SummaryValues<T> summaryValues(C identifier, FilterTableModel<?, C> tableModel, Format format) Instantiates a newSummaryModel.SummaryValues
instance.- Type Parameters:
T
- the column value typeC
- the column identifier type- Parameters:
identifier
- the column identifiertableModel
- the table modelformat
- the format- Returns:
- a new
SummaryModel.SummaryValues
instance
-
builder
public static <R,C> FilterTable.Builder<R,C> builder(FilterTableModel<R, C> tableModel, List<FilterTableColumn<C>> columns) Instantiates a newFilterTable.Builder
using the given model- Type Parameters:
R
- the type representing rowsC
- the type used to identify columns- Parameters:
tableModel
- the table modelcolumns
- the columns- Returns:
- a new
FilterTable.Builder
instance - Throws:
IllegalArgumentException
- in case the column identifiers are not unique
-
createDefaultTableHeader
- Overrides:
createDefaultTableHeader
in classJTable
-