Get the sort order for a column given a RowSorter for the TableModel containing the column. - Java Swing

Java examples for Swing:JTable Model

Description

Get the sort order for a column given a RowSorter for the TableModel containing the column.

Demo Code


//package com.java2s;

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  w w  .  jav  a 2  s  .co  m*/
     * Get the sort order for a column given a RowSorter for the TableModel
     * containing the column.
     *
     * @param rowSorter the sorter
     * @param column    the column index in the model, not the view
     * @return the sort order or {@link javax.swing.SortOrder#UNSORTED}.
     */
    @Nonnull
    public static SortOrder getSortOrder(
            @Nonnull RowSorter<? extends TableModel> rowSorter, int column) {
        for (SortKey key : rowSorter.getSortKeys()) {
            if (key.getColumn() == column) {
                return key.getSortOrder();
            }
        }
        return SortOrder.UNSORTED;
    }
}

Related Tutorials