English 中文(简体)
缩略语
原标题:Out-of-table column sorting with Glazed Lists and a JXTable

I m 采用冰川化清单进行分类和过滤。

我怎么能够区分出价的价值观? 这就是说,我希望能够以我自己的方式编订一栏价值,而按原始价值计算。

我目前的相关守则:

EventList<Foo> foos = GlazedLists.threadSafeList(new BasicEventList<Foo>());
foos.add(new Foo("bar", 5000000));

ObservableElementList.Connector<Foo> fooConnector = GlazedLists.beanConnector(Foo.class);
EventList<Foo> observedFoos = new ObservableElementList<Foo>(foos, fooConnector);

SortedList<Foo> sortedFoos = new SortedList<Foo>(observedFoos, null);

EventTableModel tableModel = new EventTableModel(sortedFoos, someTableFormat);
JXTable t = new JXTable(tableModel);

new TableComparatorChooser<Foo>(t, sortedFoos, false);

举例来说,我要将第二栏中的数值编为5.0M。 而不是5000,但如果我在名单上使用这一数值,它就会获得适当的打折。

提前感谢。

最佳回答

难道你们也许必须去掉JXTable Sorting,这样它不会干扰GL的分类? 类似:

jxtable.setSortable(false);
jxtable.setAutoCreateRowSorter(false);
jxtable.setRowSorter(null);

......,然后安装格拉茨德勒斯克斯公司 坐在桌旁:

TableComparatorChooser.install(jxtable, sortedFoos, TableComparatorChooser.SINGLE_COLUMN);

或者说,你想要在表格中将500 000 000美元作为5.0M,而不是在名单上? 然后,你只得执行你的表格。

public Object getColumnValue(E yourObject, int column)

返回人数为500 000人。

......我完全不理解这个问题,这些答案无助于解决问题。

www.un.org/Depts/DGACM/index_spanish.htm EDIT:可操作的例子......

Look at the code in the main method - especially the code with the START-END comment. I made my own very simple example, but you should understand, what I mean.

Oh... 询问班级/班级的命名情况......;-

import ca.odell.glazedlists.BasicEventList;
import ca.odell.glazedlists.EventList;
import ca.odell.glazedlists.SortedList;
import ca.odell.glazedlists.gui.TableFormat;
import ca.odell.glazedlists.swing.EventTableModel;
import ca.odell.glazedlists.swing.TableComparatorChooser;
import java.util.Comparator;
import java.util.List;
import javax.swing.ComboBoxEditor;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import org.jdesktop.swingx.JXTable;

public class Tester {

    private static class MyObject implements Comparable<MyObject> {

        private final int number;
        private final String value;

        public MyObject(int number, String value) {
            this.number = number;
            this.value = value;
        }

        public int getNumber() {
            return number;
        }

        public String getValue() {
            return value;
        }

        @Override
        public int compareTo(MyObject t) {
            return value.compareTo(t.getValue());
        }
    }

    private static class MyTableFormat implements TableFormat<MyObject> {

        @Override
        public int getColumnCount() {
            return 2;
        }

        @Override
        public String getColumnName(int i) {
            switch (i) {
                case 0:
                    return "FormattedNumber";
                case 1:
                    return "String";
                default:
                    throw new IllegalStateException();
            }
        }

        @Override
        public Object getColumnValue(MyObject e, int i) {
            switch (i) {
                case 0:
                    return getNumberString(e.getNumber());
                case 1:
                    return e.getValue();
                default:
                    throw new IllegalStateException();
            }
        }

        private Object getNumberString(int number) {
            switch (number) {
                case 1:
                    return "One";
                case 2:
                    return "Two";
                case 3:
                    return "Three";
                default:
                    throw new IllegalStateException();
            }
        }
    }

    private static class MyComparator implements Comparator<MyObject> {

        @Override
        public int compare(MyObject t, MyObject t1) {
            return Integer.valueOf(t.getNumber()).compareTo(Integer.valueOf(t1.getNumber()));
        }

    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        EventList<MyObject> list = new BasicEventList<MyObject>();
        list.add(new MyObject(1, "A"));
        list.add(new MyObject(2, "B"));
        list.add(new MyObject(3, "C"));

        SortedList<MyObject> sortedList = new SortedList<MyObject>(list);

        EventTableModel<MyObject> tableModel = new EventTableModel<MyObject>(sortedList, new MyTableFormat());
        JXTable jxtable = new JXTable(tableModel);

        /** 
         * START
         * - Deactivate JXTables build-in sorting
         * - Install GlazedLists sorting
         * - Set the comparator for the "string number" column
         */

        // deactivate sorting of JXTable
        jxtable.setSortable(false);
        jxtable.setAutoCreateRowSorter(false);
        jxtable.setRowSorter(null);

        // enable GlazedLists sorting
        TableComparatorChooser<MyObject> tcc = TableComparatorChooser.install(jxtable, sortedList, TableComparatorChooser.SINGLE_COLUMN);

        // set the comparator for your "string number" column
        List<Comparator> comparators = tcc.getComparatorsForColumn(0);
        comparators.clear();
        comparators.add(new MyComparator());

        /**
         * END
         */

        JFrame f = new JFrame("Tester");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(new JScrollPane(jxtable));
        f.pack();
        f.setVisible(true);
    }
}
问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签