使用 Glazed Lists 和 JXTable 进行表外列排序
我正在使用 Glazed Lists 来排序和过滤 JXTable。
如何对表外值进行排序?也就是说,我希望能够以自己的方式格式化列值,但对原始值进行排序。
我当前的相关代码:
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
而不是 5000000
,但是如果我在列表中使用该值,它不会正确排序。
提前致谢。
I'm using Glazed Lists to sort and filter a JXTable.
How can I sort on out-of-table values? That is, I would like to be able to format column values in my own way, yet sort on raw values.
My current relevant code:
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);
In this example, I would like to format the value in the second column as 5.0M
rather than 5000000
, but if I use this value in the list, it won't sort properly.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许您必须禁用 JXTable 排序,这样它就不会干扰 GL 排序?类似于:
... 然后在表上安装 GlazedLists TableComparatorChooser ,例如:
或者您的意思是,您想要在表中将 5000000 格式化为 5.0M,而不是在列表中?然后你只需要实现你的 TableFormat
来返回 5000000 的 5.0M 表示
。...很可能,我没有完全理解这个问题,这些答案没有帮助;-)
编辑:可运行的示例。 ..
查看 main 方法中的代码 - 特别是带有 START-END 注释的代码。
我自己做了一个非常简单的例子,但是你应该明白我的意思。
哦...抱歉类/变量/...的命名;-)
Maybe you have to disable the JXTable Sorting, so it does not interfere with the GL sorting? Something like:
... and then install GlazedLists TableComparatorChooser on the table like:
Or do you mean, you want to format 5000000 as 5.0M in the table, not in the List? Then you would only have to implement your TableFormat's
to return the 5.0M representation of 5000000.
... could well be, that I did not fully understand the problem and these answers are not helping ;-)
EDIT: Runnable example...
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... sorry for the naming of classes/variables/... ;-)