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 rows
C - the type used to identify columns
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, EventListener, Accessible, CellEditorListener, ListSelectionListener, RowSorterListener, TableColumnModelListener, TableModelListener, Scrollable

public final class FilterTable<R,C> extends JTable
A JTable implementation for SwingFilterTableModel. Note that for the table header to display you must add this table to a JScrollPane. Use builder() for FilterTable.Builder instances.
See Also:
  • Field Details

    • AUTO_RESIZE_MODE

      public static final PropertyValue<Integer> AUTO_RESIZE_MODE
      Specifies the default table column resize mode for tables in the application
    • COLUMN_REORDERING

      public static final PropertyValue<Boolean> COLUMN_REORDERING
      Specifies whether columns can be rearranged
      • Value type: Boolean
      • Default value: true
    • COLUMN_RESIZING

      public static final PropertyValue<Boolean> COLUMN_RESIZING
      Specifies whether columns can be resized
      • Value type: Boolean
      • Default value: true
    • COLUMN_TOOL_TIPS

      public static final PropertyValue<Boolean> COLUMN_TOOL_TIPS
      Specifies whether column tooltips should be enabled
      • Value type: Boolean
      • Default value: true
    • FILLS_VIEWPORT_HEIGHT

      public static final PropertyValue<Boolean> FILLS_VIEWPORT_HEIGHT
      Specifies whether or not tables are always made large enough to fill the height of an enclosing viewport
      • Value type: Boolean
      • Default value: true
    • ROWS_FILL_VIEWPORT

      public static final PropertyValue<Boolean> ROWS_FILL_VIEWPORT
      Specifies whether alternating row backgrounds are painted below the table data to fill the viewport. Note that this relies on tables filling their viewport height, see FILLS_VIEWPORT_HEIGHT
      • Value type: Boolean
      • Default value: false
      See Also:
    • RESIZE_ROW_TO_FIT_EDITOR

      public static final PropertyValue<Boolean> RESIZE_ROW_TO_FIT_EDITOR
      Specifies whether the table resizes the row being edited to fit the editor component. Only applicable to FilterTableCellEditor.
      • Value type: Boolean
      • Default value: true
    • ROW_HEIGHT_FROM_FONT_SIZE

      public static final PropertyValue<Boolean> ROW_HEIGHT_FROM_FONT_SIZE
      Specifies whether tables set their initial rowHeight according to the table font size.
      • Value type: Boolean
      • Default value: true
      See Also:
    • ROW_HEIGHT_FONT_PADDING

      public static final PropertyValue<Integer> ROW_HEIGHT_FONT_PADDING
      Specifies the number of pixels to add to the table font size to use as the initial table rowHeight.
      • Value type: Integer
      • Default value: 4
      See Also:
    • STOP_EDIT_ON_FOCUS_LOST

      public static final PropertyValue<Boolean> STOP_EDIT_ON_FOCUS_LOST
      Specifies whether the table should stop and commit editing when it loses focus.
      • Value type: Boolean
      • Default value: true
    • FILTERS

      public static final PropertyValue<FilterTable.Filters> FILTERS
      Specifies whether and where the table displays its filter panel, in the column header of its enclosing scroll pane.
      See Also:
  • Method Details

    • updateUI

      public void updateUI()
      Overrides:
      updateUI in class JTable
    • configureEnclosingScrollPane

      protected void configureEnclosingScrollPane()
      Configures the enclosing scroll pane, displaying the filter panel below the table header in the column header of the scroll pane, in case this table displays its filters.
      Overrides:
      configureEnclosingScrollPane in class JTable
      See Also:
    • getModel

      public SwingFilterTableModel<R,C> getModel()
      Overrides:
      getModel in class JTable
    • model

      public SwingFilterTableModel<R,C> model()
      Returns:
      the table model
    • getColumnModel

      public FilterTableColumnModel<C> getColumnModel()
      Overrides:
      getColumnModel in class JTable
    • columns

      public FilterTableColumnModel<C> columns()
      Returns:
      the column model
    • setModel

      public void setModel(TableModel dataModel)
      Overrides:
      setModel in class JTable
    • isCellEditable

      public boolean isCellEditable(int row, int column)
      Overrides:
      isCellEditable in class JTable
    • setColumnModel

      public void setColumnModel(TableColumnModel columnModel)
      Overrides:
      setColumnModel in class JTable
    • setSelectionModel

      public void setSelectionModel(ListSelectionModel selectionModel)
      Overrides:
      setSelectionModel in class JTable
    • getPreferredScrollableViewportSize

      public Dimension getPreferredScrollableViewportSize()
      Specified by:
      getPreferredScrollableViewportSize in interface Scrollable
      Overrides:
      getPreferredScrollableViewportSize in class JTable
    • getPopupLocation

      public @Nullable Point getPopupLocation(@Nullable MouseEvent event)
      Selects what is under the mouse before the popup menu is shown, so that the popup menu actions apply to what was clicked, where a JTable leaves the selection as is: the cell under the mouse, unless already selected, the row when right of the last column, and nothing below the last row, clearing the selection.
      Overrides:
      getPopupLocation in class JComponent
      Parameters:
      event - the mouse event triggering the popup menu, null when triggered via the keyboard
      Returns:
      the popup menu location, null for the default one
    • filters

      public TableConditionPanel<C> filters()
      Returns:
      the filter TableConditionPanel
    • search

      public FilterTableSearchModel search()
      Returns:
      the search model
    • summaries

      public TableSummaryModel<C> summaries()
      Returns:
      the summary model
    • searchField

      public JTextField searchField()
      Returns:
      the search field
    • viewport

      public Optional<JViewport> viewport()
      Returns:
      the JViewport parent of this table, an empty Optional if none exists
    • doubleClick

      public Value<Action> doubleClick()

      The Action is only triggered if enabled.

      The ActionEvent propagated when this action is performed, contains the associated MouseEvent as source.

      @Override
      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
    • sortable

      public State sortable()
      Returns:
      the State controlling whether sorting via the table header is enabled
    • setSelectionMode

      public void setSelectionMode(int selectionMode)
      Overrides:
      setSelectionMode in class JTable
    • 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 row
      column - the column
      Returns:
      true if this table is contained in a scrollpanel and the cell with the given coordinates is visible.
    • copy

      public FilterTable<R,C>.Copy copy()
      Returns:
      the FilterTable<R,C>.Copy
    • scrollTo

      public FilterTable<R,C>.ScrollTo scrollTo()
      Returns:
      the FilterTable<R,C>.ScrollTo
    • createSelectColumnsControl

      public CommandControl createSelectColumnsControl()
      Returns:
      a control for showing the column selection dialog
    • createToggleColumnsControls

      public Controls createToggleColumnsControls()
      Returns:
      Controls containing ToggleControls for showing/hiding columns.
    • createResetColumnsControl

      public CommandControl createResetColumnsControl()
      Returns:
      a Control for resetting the columns to their original location and visibility
    • createSelectAutoResizeModeControl

      public CommandControl createSelectAutoResizeModeControl()
      Returns:
      a Control for selecting the auto-resize mode
    • createToggleAutoResizeModeControls

      public Controls createToggleAutoResizeModeControls()
      Returns:
      Controls containing ToggleControls for choosing the auto resize mode.
    • createSingleSelectionControl

      public ToggleControl createSingleSelectionControl()
      Returns:
      a ToggleControl controlling whether single selection mode is enabled
    • createCopyCellControl

      public CommandControl createCopyCellControl()
      Returns:
      a Control for copying the contents of the selected cell
    • createCopyColumnControl

      public CommandControl createCopyColumnControl()
      Returns:
      a Control for copying the contents of the selected column
    • createFocusSearchFieldControl

      public CommandControl createFocusSearchFieldControl()
      Returns:
      a Control for requesting search field focus
      See Also:
      • createSearchField()
    • autoStartsEdit

      public void autoStartsEdit(boolean autoStartsEdit)
      A convenience method for setting the client property 'JTable.autoStartsEdit'.
      Parameters:
      autoStartsEdit - the value
    • doubleClicked

      public Observer<MouseEvent> doubleClicked()
      Returns:
      an observer notified each time the table is double-clicked
    • summaryValues

      public static <T extends Number, C> SummaryModel.SummaryValues<T> summaryValues(C identifier, SwingFilterTableModel<?,C> tableModel, Format format)
      Instantiates a new SummaryModel.SummaryValues instance.
      Type Parameters:
      T - the column value type
      C - the column identifier type
      Parameters:
      identifier - the column identifier
      tableModel - the table model
      format - the format
      Returns:
      a new SummaryModel.SummaryValues instance
    • builder

      public static FilterTable.Builder.ModelStep builder()
      Returns:
      a FilterTable.Builder.ModelStep instance
    • paintComponent

      protected void paintComponent(Graphics graphics)
      Overrides:
      paintComponent in class JComponent