Class SortableAndSearchableTableWithButtons<T extends SortableAndSearchableTable>

    • Field Detail

      • m_CountModelListener

        protected TableModelListener m_CountModelListener
        the model listener for updating the counts.
    • Constructor Detail

      • SortableAndSearchableTableWithButtons

        public SortableAndSearchableTableWithButtons()
        The default constructor.
      • SortableAndSearchableTableWithButtons

        public SortableAndSearchableTableWithButtons​(TableModel model)
        Initializes the table with the specified model.
        Parameters:
        model - the model to use
    • Method Detail

      • setModel

        public void setModel​(TableModel dataModel)
        Sets the data model for this table to newModel and registers with it for listener notifications from the new data model.
        Parameters:
        dataModel - the new data source for this table
        See Also:
        getModel()
      • getModel

        public TableModel getModel()
        Returns the underlying table model.
        Returns:
        the underlying table model
      • setUnsortedModel

        public void setUnsortedModel​(TableModel dataModel)
        Sets the data model for this table to newModel and registers with it for listener notifications from the new data model.
        Parameters:
        dataModel - the new data source for this table
        See Also:
        getUnsortedModel()
      • setUnsortedModel

        public void setUnsortedModel​(TableModel dataModel,
                                     boolean restoreSorting)
        Sets the data model for this table to newModel and registers with it for listener notifications from the new data model.
        Parameters:
        dataModel - the new data source for this table
        restoreSorting - whether to restore the sorting settings
        See Also:
        getUnsortedModel()
      • getUnsortedModel

        public TableModel getUnsortedModel()
        Returns the underlying table model.
        Returns:
        the underlying table model
      • supportsMovingRows

        public boolean supportsMovingRows()
        Returns whether the table model supports moving of rows.
        Returns:
        true if the model supports moving rows around
        See Also:
        MoveableTableModel
      • moveUp

        public void moveUp()
        moves the selected items up by 1.
      • moveDown

        public void moveDown()
        moves the selected items down by 1.
      • moveTop

        public void moveTop()
        moves the selected items to the top.
      • moveBottom

        public void moveBottom()
        moves the selected items to the end.
      • canMoveUp

        public boolean canMoveUp()
        checks whether the selected items can be moved up.
        Returns:
        true if the selected items can be moved
      • canMoveDown

        public boolean canMoveDown()
        checks whether the selected items can be moved down.
        Returns:
        true if the selected items can be moved
      • setColumnModel

        public void setColumnModel​(TableColumnModel columnModel)
        Sets the column model for this table to newModel and registers for listener notifications from the new column model. Also sets the column model of the JTableHeader to columnModel.
        Parameters:
        columnModel - the new data source for this table
        Throws:
        IllegalArgumentException - if columnModel is null
        See Also:
        getColumnModel()
      • setSelectionModel

        public void setSelectionModel​(ListSelectionModel newModel)
        Sets the row selection model for this table to newModel and registers for listener notifications from the new selection model.
        Parameters:
        newModel - the new selection model
        Throws:
        IllegalArgumentException - if newModel is null
        See Also:
        getSelectionModel()
      • setAutoResizeMode

        public void setAutoResizeMode​(int mode)
        Sets the table's auto resize mode when the table is resized.
        Parameters:
        mode - One of 5 legal values: AUTO_RESIZE_OFF, AUTO_RESIZE_NEXT_COLUMN, AUTO_RESIZE_SUBSEQUENT_COLUMNS, AUTO_RESIZE_LAST_COLUMN, AUTO_RESIZE_ALL_COLUMNS
        See Also:
        getAutoResizeMode(), Container.doLayout()
      • getAutoResizeMode

        public int getAutoResizeMode()
        Returns the auto resize mode of the table. The default mode is AUTO_RESIZE_SUBSEQUENT_COLUMNS.
        Returns:
        the autoResizeMode of the table
        See Also:
        setAutoResizeMode(int)
      • setOptimalColumnWidth

        public void setOptimalColumnWidth()
        Sets the optimal column width for all columns. AutoResize must be set to BaseTable.AUTO_RESIZE_OFF.
      • setOptimalColumnWidth

        public void setOptimalColumnWidth​(int column)
        Sets the optimal column width for the specified column. AutoResize must be set to BaseTable.AUTO_RESIZE_OFF.
        Parameters:
        column - the column to resize
      • setOptimalColumnWidthBounded

        public void setOptimalColumnWidthBounded​(int max)
        Sets the optimal column width for all columns. AutoResize must be set to BaseTable.AUTO_RESIZE_OFF.
        Parameters:
        max - the maximum width
      • setOptimalColumnWidthBounded

        public void setOptimalColumnWidthBounded​(int column,
                                                 int max)
        Sets the optimal column width for the specified column. AutoResize must be set to BaseTable.AUTO_RESIZE_OFF.
        Parameters:
        column - the column to resize
        max - the maximum width
      • setRowHeight

        public void setRowHeight​(int rowHeight)
        Sets the height, in pixels, of all cells to rowHeight, revalidates, and repaints. The height of the cells will be equal to the row height minus the row margin.
        Parameters:
        rowHeight - new row height
      • getRowHeight

        public int getRowHeight​(int row)
        Returns the height for the specified row.
        Parameters:
        row - the row to get the height in pixels for
        Returns:
        the row height
      • rowAtPoint

        public int rowAtPoint​(Point point)
        Returns the index of the row that point lies in, or -1 if the result is not in the range [0, getRowCount()-1].
        Parameters:
        point - the location of interest
        Returns:
        the index of the row that point lies in, or -1 if the result is not in the range [0, getRowCount()-1]
      • columnAtPoint

        public int columnAtPoint​(Point point)
        Returns the index of the column that point lies in, or -1 if the result is not in the range [0, getColumnCount()-1].
        Parameters:
        point - the location of interest
        Returns:
        the index of the column that point lies in, or -1 if the result is not in the range [0, getColumnCount()-1]
        See Also:
        rowAtPoint(java.awt.Point)
      • selectAll

        public void selectAll()
        Selects all rows.
      • selectNone

        public void selectNone()
        Deselects all rows.
      • invertSelection

        public void invertSelection()
        Inverts the selection.
      • getSelectedRow

        public int getSelectedRow()
        Returns the index of the first selected row, -1 if no row is selected.
        Returns:
        the index of the first selected row
      • setSelectedRow

        public void setSelectedRow​(int row)
        Sets the selected row (clears all others).
        Parameters:
        row - the row to select
      • getSelectedColumn

        public int getSelectedColumn()
        Returns the index of the first selected column, -1 if no column is selected.
        Returns:
        the index of the first selected column
      • getSelectedRows

        public int[] getSelectedRows()
        Returns the indices of all selected rows.
        Returns:
        an array of integers containing the indices of all selected rows, or an empty array if no row is selected
        See Also:
        getSelectedRow()
      • setSelectedRows

        public void setSelectedRows​(int[] rows)
        Sets the selected rows (clears all others).
        Parameters:
        rows - the rows to select
      • getSelectedColumns

        public int[] getSelectedColumns()
        Returns the indices of all selected columns.
        Returns:
        an array of integers containing the indices of all selected columns, or an empty array if no column is selected
        See Also:
        getSelectedColumn()
      • getSelectedRowCount

        public int getSelectedRowCount()
        Returns the number of selected rows.
        Returns:
        the number of selected rows, 0 if no rows are selected
      • getSelectedColumnCount

        public int getSelectedColumnCount()
        Returns the number of selected columns.
        Returns:
        the number of selected columns, 0 if no columns are selected
      • isRowSelected

        public boolean isRowSelected​(int row)
        Returns true if the specified index is in the valid range of rows, and the row at that index is selected.
        Returns:
        true if row is a valid index and the row at that index is selected (where 0 is the first row)
      • isColumnSelected

        public boolean isColumnSelected​(int column)
        Returns true if the specified index is in the valid range of columns, and the column at that index is selected.
        Parameters:
        column - the column in the column model
        Returns:
        true if column is a valid index and the column at that index is selected (where 0 is the first column)
      • isCellSelected

        public boolean isCellSelected​(int row,
                                      int column)
        Returns true if the specified indices are in the valid range of rows and columns and the cell at the specified position is selected.
        Parameters:
        row - the row being queried
        column - the column being queried
        Returns:
        true if row and column are valid indices and the cell at index (row, column) is selected, where the first row and first column are at index 0
      • scrollRowToVisible

        public void scrollRowToVisible​(int row)
        Scrolls the row into view.
        Parameters:
        row - the row to scroll into view
      • scrollColumnToVisible

        public void scrollColumnToVisible​(int col)
        Scrolls the column into view.
        Parameters:
        col - the column to scroll into view
      • getRowCount

        public int getRowCount()
        Returns the number of rows that can be shown in the JTable, given unlimited space. If a RowSorter with a filter has been specified, the number of rows returned may differ from that of the underlying TableModel.
        Returns:
        the number of rows shown in the JTable
        See Also:
        getColumnCount()
      • getColumnCount

        public int getColumnCount()
        Returns the number of columns in the column model. Note that this may be different from the number of columns in the table model.
        Returns:
        the number of columns in the table
        See Also:
        getRowCount()
      • getColumnName

        public String getColumnName​(int column)
        Returns the name of the column appearing in the view at column position column.
        Parameters:
        column - the column in the view being queried
        Returns:
        the name of the column at position column in the view where the first column is column 0
      • getColumnClass

        public Class<?> getColumnClass​(int column)
        Returns the type of the column appearing in the view at column position column.
        Parameters:
        column - the column in the view being queried
        Returns:
        the type of the column at position column in the view where the first column is column 0
      • getValueAt

        public Object getValueAt​(int row,
                                 int column)
        Returns the cell value at row and column.

        Note: The column is specified in the table view's display order, and not in the TableModel's column order. This is an important distinction because as the user rearranges the columns in the table, the column at a given index in the view will change. Meanwhile the user's actions never affect the model's column ordering.

        Parameters:
        row - the row whose value is to be queried
        column - the column whose value is to be queried
        Returns:
        the Object at the specified cell
      • setValueAt

        public void setValueAt​(Object aValue,
                               int row,
                               int column)
        Sets the value for the cell in the table model at row and column.

        Note: The column is specified in the table view's display order, and not in the TableModel's column order. This is an important distinction because as the user rearranges the columns in the table, the column at a given index in the view will change. Meanwhile the user's actions never affect the model's column ordering. aValue is the new value.

        Parameters:
        aValue - the new value
        row - the row of the cell to be changed
        column - the column of the cell to be changed
        See Also:
        getValueAt(int, int)
      • isCellEditable

        public boolean isCellEditable​(int row,
                                      int column)
        Returns true if the cell at row and column is editable. Otherwise, invoking setValueAt on the cell will have no effect.

        Note: The column is specified in the table view's display order, and not in the TableModel's column order. This is an important distinction because as the user rearranges the columns in the table, the column at a given index in the view will change. Meanwhile the user's actions never affect the model's column ordering.

        Parameters:
        row - the row whose value is to be queried
        column - the column whose value is to be queried
        Returns:
        true if the cell is editable
        See Also:
        setValueAt(java.lang.Object, int, int)
      • setSelectionMode

        public void setSelectionMode​(int selectionMode)
        Sets the table's selection mode to allow only single selections, a single contiguous interval, or multiple intervals.
        Parameters:
        selectionMode - the selection mode to use
        See Also:
        JList.setSelectionMode(int)
      • updateCountsModelListener

        protected void updateCountsModelListener​(TableModel dataModel)
        Updates the table model's listener for updating the counts.
        Parameters:
        dataModel - the model to update
      • updateCounts

        protected void updateCounts()
        Updates the information about the counts.
      • getActualRow

        public int getActualRow​(int visibleRow)
        Returns the actual underlying row the given visible one represents. Useful for retrieving "non-visual" data that is also stored in a TableModel.
        Parameters:
        visibleRow - the displayed row to retrieve the original row for
        Returns:
        the original row
      • getDisplayRow

        public int getDisplayRow​(int internalRow)
        Returns the "visible" row derived from row in the actual table model.
        Parameters:
        internalRow - the row in the actual model
        Returns:
        the row in the sorted model, -1 in case of an error
      • addRemoveItemsListener

        public void addRemoveItemsListener​(RemoveItemsListener l)
        Adds the remove items listener to its internal list.
        Parameters:
        l - the listener to add
      • removeRemoveItemsListener

        public void removeRemoveItemsListener​(RemoveItemsListener l)
        Removes the remove items listener from its internal list.
        Parameters:
        l - the listener to remove
      • addHeaderPopupMenuListener

        public void addHeaderPopupMenuListener​(PopupMenuListener l)
        Adds the popup menu listeners for the header.
        Parameters:
        l - the listener to add
      • removeHeaderPopupMenuListener

        public void removeHeaderPopupMenuListener​(PopupMenuListener l)
        Removes the popup menu listener for the header from its internal list.
        Parameters:
        l - the listener to remove
      • addCellPopupMenuListener

        public void addCellPopupMenuListener​(PopupMenuListener l)
        Adds the popup menu listeners for the cell.
        Parameters:
        l - the listener to add
      • removeCellPopupMenuListener

        public void removeCellPopupMenuListener​(PopupMenuListener l)
        Removes the popup menu listener for the cell from its internal list.
        Parameters:
        l - the listener to remove
      • search

        public void search​(String searchString,
                           boolean regexp)
        Performs a search for the given string. Limits the display of rows to ones containing the search string.
        Parameters:
        searchString - the string to search for
        regexp - whether to perform regular expression matching or just plain string comparison
      • getSeachString

        public String getSeachString()
        Returns the current search string.
        Returns:
        the search string, null if not filtered
      • isRegExpSearch

        public boolean isRegExpSearch()
        Returns whether the last search was a regular expression based one.
        Returns:
        true if last search was a reg exp one
      • setShowSimplePopupMenus

        public void setShowSimplePopupMenus​(boolean value)
        Sets whether to show a simple header/cell popup menu.
        Parameters:
        value - true if to show menus
      • setShowSimpleHeaderPopupMenu

        public void setShowSimpleHeaderPopupMenu​(boolean value)
        Sets whether to show a simple header popup menu.
        Parameters:
        value - true if to show menu
      • getShowSimpleHeaderPopupMenu

        public boolean getShowSimpleHeaderPopupMenu()
        Returns whether to show a simple header popup menu.
        Returns:
        true if to show menu
      • setShowSimpleCellPopupMenu

        public void setShowSimpleCellPopupMenu​(boolean value)
        Sets whether to show a simple cell popup menu.
        Parameters:
        value - true if to show menu
      • getShowSimpleCellPopupMenu

        public boolean getShowSimpleCellPopupMenu()
        Returns whether to show a simple cell popup menu.
        Returns:
        true if to show menu