如何使 JTable 不在事件线程上排序?
所以我有一个昂贵的排序,可以使用IO或从网络抓取数据来帮助它排序。
我的问题是 JTable 排序位于事件线程上,因此冻结了 GUI。
我该如何改变它,让它不出现?
So I have an expensive sort that can use IO or grabbing data from the net to help it sort.
My problem is that JTable sort is on the event thread and therefore freezes the GUI.
How do I change it so it doesn't?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从 Java 6 开始,出现了
RowSorter
接口。我自己还没有处理过它,但看起来应该可以异步实现它并在完成时通知表(或者这甚至可能已经是它的默认行为)。Since Java 6, there's the
RowSorter
interface. I haven't dealt with it myself, but it looks as though it should be possible to implement it asynchronously and notify the table when it's done (or that may even already be its default behaviour).您可以启动一个新线程并传递一个匿名 Runnable 实例:
You can start a new Thread and pass a anonymous Runnable instance:
我确实有一个解决方案,但我忘记发布了。但还是不够完美,所以最后我就用了一个表库。
Glazed Lists 非常适合处理排序和查看大量数据:
http://www.glazedlists.com/
I did have a solution which I forgot to post. But still wasn't perfect, so in the end I just used a table library.
Glazed lists is quite good in dealing with sorting and viewing large sets of data:
http://www.glazedlists.com/