Is it possible to invoke the auto row sorter in a jtable

荒凉一梦 提交于 2019-12-10 14:17:01

问题


is there anyway to invoke the auto row sorter in a jtable that is created by using

setAutoCreateRowSorter(true);

i'm trying to get it to sort by a default column without the user having to click on on the column header.


回答1:


table.getRowSorter().toggleSortOrder(modelColumnIndex)



回答2:


TableRowSorter rowSorter = (TableRowSorter) table.getRowSorter();
List<SortKey> keys = new ArrayList<SortKey>();
SortKey sortKey = new SortKey(2, SortOrder.ASCENDING);//column index 2
keys.add(sortKey);
rowSorter.setSortKeys(keys);
rowSorter.sort();



回答3:


i'm trying to get it to sort by a default column without the user having to click on on the column header.

I think you have to use setSortsOnUpdates(true) method from TableRowSorter class.



来源:https://stackoverflow.com/questions/7903833/is-it-possible-to-invoke-the-auto-row-sorter-in-a-jtable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!