Java JTable Row Sort setSortOrder(@Nonnull RowSorter rowSorter, int column, @Nonnull SortOrder sortOrder)

Here you can find the source of setSortOrder(@Nonnull RowSorter rowSorter, int column, @Nonnull SortOrder sortOrder)

Description

Set the sort order for a table using the specified column given a RowSorter for the TableModel containing the column.

License

Open Source License

Parameter

Parameter Description
rowSorter the sorter
column the column index in the model, not the view
sortOrder the sort order

Declaration

public static void setSortOrder(@Nonnull RowSorter<? extends TableModel> rowSorter, int column,
        @Nonnull SortOrder sortOrder) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Nonnull;
import javax.swing.RowSorter;
import javax.swing.RowSorter.SortKey;
import javax.swing.SortOrder;

import javax.swing.table.TableModel;

public class Main {
    /**//from w ww .  j  a  v  a 2 s .  com
     * Set the sort order for a table using the specified column given a
     * RowSorter for the TableModel containing the column.
     * <p>
     * This makes all other columns unsorted, even if the specified column is
     * also specified to be unsorted.
     *
     * @param rowSorter the sorter
     * @param column    the column index in the model, not the view
     * @param sortOrder the sort order
     */
    public static void setSortOrder(@Nonnull RowSorter<? extends TableModel> rowSorter, int column,
            @Nonnull SortOrder sortOrder) {
        List<SortKey> keys = new ArrayList<>();
        if (!sortOrder.equals(SortOrder.UNSORTED)) {
            keys.add(new RowSorter.SortKey(column, sortOrder));
        }
        rowSorter.setSortKeys(keys);
    }
}

Related

  1. applyRowSorter(JTable table)
  2. createTableRowSorter(Class clazz, TableModel model)
  3. filt(ArrayList selectedLevel, String text, TableRowSorter sorter)
  4. getSortOrder(@Nonnull RowSorter rowSorter, int column)
  5. jtable$setAutoCreateRowSorter(JTable table)
  6. tryToEnableRowSorting(JTable listTbl)