Java JTable Column isColumnSorted(JTable table, int column)

Here you can find the source of isColumnSorted(JTable table, int column)

Description

Returns whether a table column is sorted.

License

Open Source License

Parameter

Parameter Description
table - the table to check
column - the column in the table to check.

Return

boolean - whether the column is sorted or not.

Declaration

public static boolean isColumnSorted(JTable table, int column) 

Method Source Code


//package com.java2s;

import java.util.List;
import javax.swing.JTable;
import javax.swing.RowSorter;
import javax.swing.RowSorter.SortKey;

public class Main {
    /**/*from w ww .  j a v a  2 s .c o  m*/
     * Returns whether a table column is sorted.
     * @param table - the table to check
     * @param column - the column in the table to check.
     * @return boolean - whether the column is sorted or not.
     */
    public static boolean isColumnSorted(JTable table, int column) {
        boolean isSorted = false;
        final int modelColumn = table.convertColumnIndexToModel(column);
        RowSorter sorter = table.getRowSorter();
        if (sorter != null) {
            List<? extends SortKey> sortKeys = sorter.getSortKeys();
            for (SortKey sortKey : sortKeys) {
                if (sortKey.getColumn() == modelColumn) {
                    isSorted = true;
                    break;
                }
            }
        }
        return isSorted;
    }
}

Related

  1. getRenderedComponentAt(JTable table, int row, int column)
  2. getTableColumn(JTable table, int columnIndex)
  3. hideColumn(JTable table, int columnIndex)
  4. installDelegatingColumn(TableColumn column, String label)
  5. isColumnDefinitionChange(TableModelEvent e)
  6. isNotDuplicateKeyOfTable(String text, TableModel model, int column)
  7. layoutColumns(JTable p_Table, boolean p_OnlyVisibleRows)
  8. loadToTableModel(String fileName, Object[] columns)
  9. makeTablePanel(int rows, int cols, int mainColumn, JComponent components[])