Package jmri.swing

Class RowSorterUtil


  • public final class RowSorterUtil
    extends java.lang.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 Summary

      Constructors 
      Constructor Description
      RowSorterUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static javax.swing.event.RowSorterListener addSingleSortableColumnListener​(javax.swing.RowSorter<? extends javax.swing.table.TableModel> rowSorter)
      Add a RowSorterListener to the rowSorter that prevents multiple columns from being considered while sorting.
      static javax.swing.SortOrder getSortOrder​(javax.swing.RowSorter<? extends javax.swing.table.TableModel> rowSorter, int column)
      Get the sort order for a column given a RowSorter for the TableModel containing the column.
      static void setSortOrder​(javax.swing.RowSorter<? extends javax.swing.table.TableModel> rowSorter, int column, javax.swing.SortOrder sortOrder)
      Set the sort order for a table using the specified column given a RowSorter for the TableModel containing the column.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getSortOrder

        @Nonnull
        public static javax.swing.SortOrder getSortOrder​(@Nonnull
                                                         javax.swing.RowSorter<? extends javax.swing.table.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
                                        javax.swing.RowSorter<? extends javax.swing.table.TableModel> rowSorter,
                                        int column,
                                        @Nonnull
                                        javax.swing.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

        public static javax.swing.event.RowSorterListener addSingleSortableColumnListener​(@Nonnull
                                                                                          javax.swing.RowSorter<? extends javax.swing.table.TableModel> rowSorter)
        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:
        java.lang.NullPointerException - if rowSorter is null