get Sort Key from JTable by Column - Java Swing

Java examples for Swing:JTable Column

Description

get Sort Key from JTable by Column

Demo Code


//package com.java2s;

import java.util.List;

import javax.swing.JTable;
import javax.swing.RowSorter;
import javax.swing.RowSorter.SortKey;

public class Main {
    public static SortKey getSortKey(JTable table, int column) {
        RowSorter rowSorter = table.getRowSorter();
        if (rowSorter == null) {
            return null;
        }/*from  ww  w .j  av a 2s . c  o m*/

        List sortedColumns = rowSorter.getSortKeys();
        if (!sortedColumns.isEmpty()) {
            return (SortKey) sortedColumns.get(0);
        }
        return null;
    }
}

Related Tutorials