Package jmri.swing

Class RowSorterUtil

java.lang.Object
jmri.swing.RowSorterUtil

public final class RowSorterUtil extends Object
Utilities for handling JTable row sorting, assuming only a single column influences the table sort order.

Multi-column sorting should be controlled by directly manipulating the RowSorter.SortKeys returned by RowSorter.getSortKeys().

  • Constructor Details

  • Method Details

    • getSortOrder

      @Nonnull public static SortOrder getSortOrder(@Nonnull RowSorter<? extends TableModel> rowSorter, int column)
      Get the sort order for a column given a RowSorter for the TableModel containing the column.
      Parameters:
      rowSorter - the sorter
      column - the column index in the model, not the view
      Returns:
      the sort order or SortOrder.UNSORTED.
    • setSortOrder

      public static void setSortOrder(@Nonnull RowSorter<? extends TableModel> rowSorter, int column, @Nonnull SortOrder sortOrder)
      Set the sort order for a table using the specified column given a RowSorter for the TableModel containing the column.

      This makes all other columns unsorted, even if the specified column is also specified to be unsorted.

      Parameters:
      rowSorter - the sorter
      column - the column index in the model, not the view
      sortOrder - the sort order
    • addSingleSortableColumnListener

      Add a RowSorterListener to the rowSorter that prevents multiple columns from being considered while sorting.
      Parameters:
      rowSorter - the sorter to add the listener to
      Returns:
      the added listener
      Throws:
      NullPointerException - if rowSorter is null