许多图形组件以什么方式影响 Swing GUI 的性能?

发布于 2024-07-25 07:46:43 字数 674 浏览 7 评论 0原文

我创建了一个 Java Swing 应用程序,我意识到表单上有很多组件。

并不是说我的界面杂乱,但总量还是可以的相当高(数百),因为用户可以启用界面的其他部分,并且表单上必须有类似列表的重复面板。

此外,许多组件被包装到 JXLayer 中,再次增加了可视组件的数量。

到目前为止,除了滚动和调整大小过程中的滞后之外,我还没有发现任何问题。

  • 组件数量有理论上的限制吗? (我对此表示怀疑,但我也必须用 VB6 编写代码,所以我一直在那里......)
  • 有任何实际限制吗? 在工作中,我们有一些中端工作站,乍一看表现良好,但是 Java/Swing 在低端工作站或极端数量的组件上有何反应?
  • 除了检查用户的主观印象之外,还有什么方法可以分析我的应用程序的 GUI? 是否有任何我可以寻找的客观指标(例如在 javax.swing.SwingCoreClassWhichContainsBottleneckCode 或其他内容上花费的总时间...)

I've creating a Java Swing application and I realized that I have many many components on a form.

It's not that my interface is cluttered, but nevertheless the total amount can be quite high (hundreds) because the user can enable additional parts of the interface and there have to be list-like repeating panels on the form.

Additionally many components are wrapped into a JXLayer, again increasing the number of visual components.

Until now I couldn't detect any problems besides lagging during scrolling and resizing.

  • Are there any theoretical limits on the number of components? (I doubt it, but I also have to code in VB6, so I've been there...)
  • Are there any pratical limits? At work we have some medium-end workstations which perform fine at first sight, but how does Java/Swing react on low-end workstations or extreme counts of components?
  • Is there any way to profile the GUI of my application besides checking the subjective impression of the user? Are there any objective indicators I can look for (Like total time spent in javax.swing.SwingCoreClassWhichContainsBottleneckCode or something...)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

韵柒 2024-08-01 07:46:43

Swing 可以处理大量组件,但内存有限,特别是使用简单组件(文本框、标签、单选按钮等)。 有一些技巧,例如减小窗口大小并将所有内容包装在 JScrollPane 中,但通常标准技术(例如在后台进行繁重处理)就足够了。

我公司正在开发的功能之一涉及一个带有重复 JPanel 的对话框,其中包含一些标签和一个按钮。 我们在旧的 Mac Mini(英特尔酷睿独奏,512mb 内存)上进行了测试,创建 500 个面板需要几秒钟的时间来加载,但之后滚动面板列表或添加新面板一点也不慢。

对于严重的性能问题,请查看 JTable 它针对显示大量数据进行了高度优化。 创建自定义渲染器和编辑器有点困难,但并非不可能。

Swing can handle a significant number of components with only memory limitations, particularly using simple components (text box, label, radio button etc). There are some tricks eg reducing the window size and wrapping everything in a JScrollPane, but generally standard techniques such as doing heavy processing in the background will be all you need.

One of the features my company is working on involves a dialog with a repeating JPanel that contains a handful of labels and a button. We tested it on our old Mac Mini (intel core solo with 512mb ram) and creating 500 panels took a few seconds to load but after that scrolling through the panel list or adding new panels was not slow at all.

For serious performance concerns look at JTable which is pretty highly optimised for displaying large amounts of data. It's a little tough to create custom renderers and editors, but not impossible.

半世蒼涼 2024-08-01 07:46:43

只有内存和底层操作系统限制了组件的数量。

实际限制有点用户主观。 尝试将 UI 拆分为单独的选项卡或 JFrame,这将限制每个屏幕的渲染开销。

JVisualVM 在分析 java 应用程序方面非常出色。 您需要删除类过滤器才能查看分析的 sun* 和 javax* 类。

Only the memory and the underlying OS limits the number of components.

The practical limit is a bit user-subjective. Try splitting the UI into separate tabs or JFrames, this will limit the rendering overhead per screen.

JVisualVM is quite good in profiling java application. You will need to remove the class filters to see the sun* and javax* classes profiled.

离不开的别离 2024-08-01 07:46:43
  1. 理论上,您可以拥有任意数量的组件。

  2. 实际限制是 RAM 的数量。 此外,当组件太多时,UI 会开始变慢,因此性能也是一个问题(一如既往)。 Java 6 会有所帮助。

  3. 是的。 您可以创建 UI,然后在 shell 级别强制重新绘制(以便所有内容都被绘制)并进行测量。 使用探查器应该可以让您了解哪个组件特别慢。

  1. In theory, you can have as many components as you like.

  2. The practical limit is the amount of RAM. Also, the UI will start to get slow when you have too many components, so performance is an issue, too (as always). Java 6 will help a bit.

  3. Yes. You can create the UI and then force a repaint at the shell level (so everything gets painted) and measure that. Using a profiler should give you some idea which component is especially slow.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文