I have a GlazedList table which has 3 columns. I can sort decedent and ascendant manually by clicking on the header of columns.
My question is how to sort the table from begin when application start up? I means the table be ascendant sorted automatically according second column.
// 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);
Edited:
Just add .appendComparator(1,0,true)
to the TableComparatorChooser
as below.
TableComparatorChooser.install(codeTable, codeSortedList, TableComparatorChooser.MULTIPLE_COLUMN_MOUSE).appendComparator(1,0,true);
Just add .appendComparator(1,0,true)
to the TableComparatorChooser
as below.
TableComparatorChooser.install(codeTable, codeSortedList, TableComparatorChooser.MULTIPLE_COLUMN_MOUSE).appendComparator(1,0,true);