Sorting Jtable按列排序

Sorting Jtable按列排序,sorting,jtable,Sorting,Jtable,JTable 校长1 |校长2 |校长3 temp1 | temp1 | Boolean.FALSE temp2 | temp2 | Boolean.TRUE temp3 | temp3 | Boolean.FALSE temp4 | temp4 | Boolean.TRUE 我怎样才能给Header3分类?先输入Boolean.TRUE,然后输入Boolean.FALSE。您可以使用TableRowSorter进行排序。搜索它,你会得到大量的例子 我不知道如何将第三列设置为要排序的列 参照和,

JTable

校长1 |校长2 |校长3

temp1 | temp1 | Boolean.FALSE

temp2 | temp2 | Boolean.TRUE

temp3 | temp3 | Boolean.FALSE

temp4 | temp4 | Boolean.TRUE


我怎样才能给Header3分类?先输入Boolean.TRUE,然后输入Boolean.FALSE。

您可以使用TableRowSorter进行排序。搜索它,你会得到大量的例子

我不知道如何将第三列设置为要排序的列

参照和,您可以像这样为
检查列指定列和
排序器

public CheckABunch() {
    ...
    table.setAutoCreateRowSorter(true);
    DefaultRowSorter<DefaultTableModel, Integer> sorter =
        ((DefaultRowSorter) table.getRowSorter());
    List<RowSorter.SortKey> sortKeys = new ArrayList<RowSorter.SortKey>();
    sortKeys.add(new RowSorter.SortKey(CHECK_COL, SortOrder.DESCENDING));
    sorter.setSortKeys(sortKeys);
}
public CheckABunch(){
...
表.setAutoCreateRowSorter(真);
默认行分拣机=
((DefaultRowSorter)table.getRowSorter());
List sortKeys=new ArrayList();
添加(新的行分拣机SortKey(检查列,分拣机下降));
分拣机设置快捷键(快捷键);
}

我已经试过了,但我不知道如何将第三列设置为要排序的列。我可以知道您为什么要这样做吗?