简体   繁体   English

使用Java中的大量组件优化JFrame的绘制

[英]Optimizing painting of a JFrame with a large number of components in Java

So I have the following problem. 所以我有以下问题。 I create a JInternalFrame with a VERY LARGE NUMBER of components (lets say 50 000 of text areas). 我创建了一个JInternalFrame,其中包含非常大的组件数(假设有50 000个文本区域)。 First I do all the logic ( capture all the data which is displayed in the text areas ) and after I set the frame visible, what makes the program freeze ( I suppose it paints all the components). 首先,我执行所有逻辑(捕获文本区域中显示的所有数据),然后在我将框架设置为可见之后,程序冻结的原因(我想它会绘制所有组件)。

What would be the best way to optimize the painting ? 优化绘画的最佳方法是什么? I guess I should use separate threads so the program wont freeze, but what would be the best approach ? 我想我应该使用单独的线程,所以程序不会冻结,但最好的方法是什么? Should I set the frame visible first and then do the login in a thread or should I do all the login and then paint it in a thread ( if so how to paint child components apart from the parent ), or maybe something else ? 我应该首先设置框架可见,然后在线程中进行登录,还是应该执行所有登录,然后将其绘制在一个线程中(如果是这样,如何绘制除父级之外的子组件),或者其他什么?

Thanks in advance 提前致谢

Swing components may not be used outside of the EDT. 摆动组件不得在EDT之外使用。 So adding threads is not an option. 因此添加线程不是一种选择。 The obvious option is not to have as many components. 显而易见的选择是没有尽可能多的组件。 A UI with 50,000 text areas is unusable. 具有50,000个文本区域的UI无法使用。 Redesign the UI. 重新设计UI。

One problem is the layouting on calling pack() . 一个问题是调用pack()的布局。 The appropiate LayoutManager and set(Preffered|Minimum|Maximum)Size will help. 适当的LayoutManager和设置(优先|最小|最大)大小将有所帮助。

It seems you are doing a kind of spread sheet , inside a JScrollPane. 看来你在JScrollPane里面做了一种电子表格 In that case a JTable might help, with a virtual model, with text areas on mouse hoover. 在这种情况下,JTable可以通过虚拟模型帮助鼠标悬停上的文本区域。 (A JTable reuses the same component for different cells.) (JTable为不同的单元重用相同的组件。)

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

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