[英]Multiple column sort in JTable
I know that JTable
can sort by a single column. 我知道
JTable
可以按单列排序。 But is it possible to allow for multiple column sort or do I need to write the code myself? 但是是否可以允许多列排序或者我是否需要自己编写代码?
在您正在使用的RowSorter
调用setSortKeys
,可以通过指定多个排序键来按多列排序。
You should be able to set the TableRowSorter and the Comparator associated with it. 您应该能够设置TableRowSorter和与之关联的Comparator。 Example:
例:
TableModel myModel = createMyTableModel();
JTable table = new JTable(myModel);
TableRowSorter t = new TableRowSorter(myModel);
t.setComparator(column that the comparator works against, Comparator<?> comparator);
table.setRowSorter(new TableRowSorter(myModel));
ETable from the netbeans collection. 来自netbeans集合的ETable。
It is part of org-netbeans-swing-outline.jar 它是org-netbeans-swing-outline.jar的一部分
A google search aught to turn it up. 一个谷歌搜索应该打开它。 The ETable is primarily a foundation for Outline (a TreeTable) but it has multi-column ordering built in as well as many other nice features
ETable主要是Outline(一个TreeTable)的基础,但它内置了多列排序以及许多其他不错的功能
"I know that Jtable can sort by a single column. But is it possible to allow for multiple column sort or do i need to write the code myself? " “我知道Jtable可以按单列排序。但是是否可以允许多列排序或者我是否需要自己编写代码?”
Table sorting and filtering is managed by a sorter object. 表排序和过滤由分拣机对象管理。 The easiest way to provide a sorter object is to set autoCreateRowSorter bound property to true;
提供分拣器对象的最简单方法是将autoCreateRowSorter bound属性设置为true;
JTable table = new JTable();
table.setAutoCreateRowSorter(true);
This action defines a row sorter that is an instance of javax.swing.table.TableRowSorter. 此操作定义行排序器,它是javax.swing.table.TableRowSorter的实例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.