Here you can find the source of setSortOrder(@Nonnull RowSorter extends TableModel> rowSorter, int column, @Nonnull SortOrder sortOrder)
Parameter | Description |
---|---|
rowSorter | the sorter |
column | the column index in the model, not the view |
sortOrder | the sort order |
public static void setSortOrder(@Nonnull RowSorter<? extends TableModel> rowSorter, int column, @Nonnull SortOrder sortOrder)
//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); } }