使用JTable显示流数据的性能下降 [英] Sluggish Performance Using JTable Displaying Streaming Data

查看:115
本文介绍了使用JTable显示流数据的性能下降的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我引用的代码是专有的,需要多播服务器,因此我无法发布SSCCE代码段。我理解这可能会排除任何有用的洞察力,这些洞察力会引起可行的反应...

The code I'm referencing is proprietary and requires a multicast server, so I can't post an SSCCE snippet. I understand this may preclude any helpful insight which would elicit viable responses...

我正在使用Java 7 u 9进行编译。

I'm compiling with Java 7 u 9.

我目前正在GUI应用程序中使用JTable来监听多播数据,并在它到达时显示它。滚动表格或调整列大小时,应用程序响应速度极慢。

I'm currently using a JTable in a GUI app that listens to multicast data, and displays it as it arrives. When scrolling the table or resizing columns, the app responds excruciatingly slow.

我认为我的代码编排得恰当。

I thought I structured my code appropriately.

我使用了一个包装类,在它的main()函数中,它创建了一个自身的实例,它处理命令行参数,创建监听器,创建JFrame和调用返回JTable的类。这都是在事件派发线程之外完成的。

I used a wrapper class, and in it's main() function, it creates an instance of itself, which processes command line arguments, creates listeners, creates the JFrame and calls the class that returns a JTable. This is all done outside of the event dispatch thread.

然后,在下一行中,我使用invokeLater()方法创建一个处理所有GUI的线程渲染。它创建一个JScrollPane,将JTable添加到滚动窗格,设置滚动条,设置视口,设置滚动模式,以及将JScrollPane添加到JFrame。这都是在事件派发线程中处理的。

Then, in the next line, I used the invokeLater() method to create a thread that handles all of the GUI rendering. It creates a JScrollPane, adds the JTable to the scroll pane, sets the scroll bars, sets the viewport, sets the scroll mode, and adds the JScrollPane to a JFrame . This is all handled within the event dispatch thread.

这些行通常填充得相当快,偶尔会有屏幕冻结(某些行包含30行或更多行),但是响应能力似乎可以接受。但是,在滚动或调整列大小时,响应非常慢。

The rows typically populate fairly quick, with the occasional screen freeze (some of the rows contain 30 or more lines), but the responsiveness seems acceptable. However, when scrolling or resizing columns, the response is very slow.

我见过的所有示例,包括SwingX SwingLabs演示都引用了一个初始数据集,装在前面。我需要一个使用JTable和流数据的例子。

All of the examples I've seen, including the SwingX SwingLabs demo all refer to an initial dataset that is loaded up front. I need an example of using a JTable with streaming data.

有人能指点我这样的例子/演示吗?

Can anyone point me to such an example/demo?

这是我的main()片段...

This is my main() snippet...

public static void main(String args[]) 
{
    final JXTrapTableGUI ttg = new JXTrapTableGUI(args);
    SwingUtilities.invokeLater(new Runnable()
    {
        public void run() 
        {
            ttg.createAndShowGUI();
        }
    });
}

PS。我要感谢每一位回复的人。我已被推迟到3月11日这个项目,但我将审查该日期的所有回复。

PS. I want to thank each and everyone who responded. I've been pulled off this project until March 11th, but I will review all responses on that date.

推荐答案

我不知道认为JTable可以很好地处理流数据。如果TableModel不包含实际列表而是与数据流的某些连接,那么您提到的所有优化技术(如保持处理事件调度线程)都是不相关的。

I do not think that JTable works well with streaming data at all. All of the optimization techniques you mentioned, like keeping processing off of the Event Dispatch Thread, are irrlevant if the TableModel does not contain a real list but instead some connection to a data stream.

如果没有看到你试图如何处理这个问题,很难确切知道它为什么会变慢。但是我将如何使它成为repsonsive:
创建一个存储List的ListModel - 不是对流的引用,只是一个普通的List。
让另一个线程从流中捕获多播数据,让我们称之为 DataStreamCollector
然后启动一个在计时器( javax.swing.Timer )上运行的线程,该计时器使用 DataStreamCollector 并根据需要更新ListModel。

Without seeing how you attempted to handle this, it's hard to know exactly why it's slow. But here is how I would make it repsonsive: Create a ListModel that stores a List - not a reference to a stream, just a plain List. Have another Thread capture Multicast Data from the stream, lets call it DataStreamCollector. Then launch a Thread that runs on a timer (javax.swing.Timer) that checks with the DataStreamCollector and updates the ListModel as needed.

我的设计假设UI响应比100%与数据流同步更重要。调整计时器可以让您在拥有响应式用户界面的最新表格中进行权衡。

My design here is assuming that UI responsiveness is more important than 100% synchronization with the data stream. Adjusting the timers should let you trade off having an up-to-date table with having a responsive UI.

这篇关于使用JTable显示流数据的性能下降的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆