简体   繁体   English

如何以编程方式对第二列的glazedList表进行排序?

[英]How programmatically sort glazedList table ascendant acording second column?

I have a GlazedList table which has 3 columns. 我有一个包含3列的GlazedList表。 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. 编辑:只需将.appendComparator(1,0,true)添加到TableComparatorChooser ,如下所示。

TableComparatorChooser.install(codeTable, codeSortedList, TableComparatorChooser.MULTIPLE_COLUMN_MOUSE).appendComparator(1,0,true);

只需将.appendComparator(1,0,true)添加到TableComparatorChooser ,如下所示。

TableComparatorChooser.install(codeTable, codeSortedList, TableComparatorChooser.MULTIPLE_COLUMN_MOUSE).appendComparator(1,0,true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM