我有一个 GlazedList 表,它有 3 列。我可以通过单击列标题手动对死者和升序进行排序。
我的问题是如何在应用程序启动时对表格进行排序? 我的意思是表格根据第二列自动升序排序。
// Build a filter
FilterList<Code> radioFilterList = new FilterList<Code>(CodeModel.getCodeEventList(), new ThreadedMatcherEditor<Code>(filterPanel.getCodeMatcherEditor()));
TextFilterator<Code> CodeTextFilterator = new TextFilterator<Code>() {
public void getFilterStrings(java.util.List<String> strings, Code Code) {
strings.add(Code.getName());
strings.add(String.valueOf(Code.getDate()));
strings.add(String.valueOf(Code.getSize()));
}
};
MatcherEditor<Code> textMatcherEditor = new TextComponentMatcherEditor<Code>(filterPanel.getTextComponent(), CodeTextFilterator);
filterList = new FilterList<Code>(radioFilterList, new ThreadedMatcherEditor<Code>(textMatcherEditor));
// Build a JTable
String[] propertyNames = new String[]{"name", "date", "size"};
String[] columnLabels = new String[]{"Code Name", "Code Date", "Size"};
TableFormat<Code> tableFormat = GlazedLists.tableFormat(Code.class, propertyNames, columnLabels);
CodeSortedList = new SortedList<Code>(filterList, null);
CodeTable = new JTable(new EventTableModel<Code>(CodeSortedList, tableFormat));
TableComparatorChooser.install(CodeTable, CodeSortedList, TableComparatorChooser.MULTIPLE_COLUMN_MOUSE);
// Configure the JTable
CodeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
CodeTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
编辑:
只需添加.appendComparator(1,0,true)
如下TableComparatorChooser
。
TableComparatorChooser.install(codeTable, codeSortedList, TableComparatorChooser.MULTIPLE_COLUMN_MOUSE).appendComparator(1,0,true);