当前位置: 动力学知识库 > 问答 > 编程问答 >

java - how to force sort on a JTable

问题描述:

I already have this:

TableRowSorter<FileTableModel> rs = new TableRowSorter<FileTableModel>(ftm);

rs.setComparator(COL_NAME, new Comparator<DisplayFile>() {

//<sorting code>

}

});

setRowSorter(rs);

and it works. It sorts the rows as it should when the user clicks on the header.

I just can't figure out an easy way to sort the rows without the click on the header.

I want rows to already be sorted when they are displayed (user can then change asc/desc/etc. by clicking on column headers.)

How can i force the sorting? I know I could sort the rows in my TableModel, but i already have a working comparator, why not use it?

网友答案:
rowSorter.toggleSortOrder(colIndex);
分享给朋友:
您可能感兴趣的文章:
随机阅读: