构建 gui 组件树的首选方法

发布于 2024-07-26 22:11:55 字数 196 浏览 4 评论 0原文

构建应用程序 gui 组件树的首选方法是什么?

  1. 实例化所有组件并构建整个树,通过对用户事件的显示/隐藏/禁用/启用操作来控制它。

    实例化所有组件并构建整个树
  2. 使用基于用户事件的创建/添加/删除组件动态创建 gui。

我对 JavaFX 中的这个设计问题特别感兴趣。

What is the preferred way to build application gui components tree?

  1. Instantiate all components and build an entire tree, controlling it with show/hide/disable/enable operations on user events.

  2. Dynamically creating gui with create/add/remove components based on user events.

I'm especially interested with this design problem in JavaFX.

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

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

发布评论

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

评论(2

白昼 2024-08-02 22:11:55

抱歉,我对JavaFX了解不多。

但是,我建议选择 2。如果您在开始时实例化所有内容,那么当您实际上只需要为当前可见的 gui 组件使用内存时,您将耗尽整个内存负载。

为当前屏幕创建所有组件,并显示/隐藏/禁用/启用它们。 但不要创建不在当前屏幕/窗口/表单/对话框上的组件。

Sorry, I don't know much about JavaFX.

But, I would suggest option 2. If you instantiate everything at the start, you're going to use up a whole load of memory when you only actually need to use memory for the gui components that are currently visible.

Create all of the components for the current screen, and show/hide/disable/enable them. But don't create components that don't live on the current screen/window/form/dialog.

泪眸﹌ 2024-08-02 22:11:55

答案主要取决于性能。 我已经毫无问题地构建了大约 3000 个节点的树。 在某个时间点,添加到场景中的节点数量确实会影响性能,但这是一个不断变化的目标,因为 JavaFX 的每个版本都在这方面进行改进。

然而,并非所有性能下降都是由于节点数量造成的,因为它可能是由于“BindStorming”造成的。 请参阅 Jim Connors 博客,了解此帖子以及其他与性能相关的帖子。

The answer depends mainly on performance. I have built trees with ~3000 nodes with no problem. At some point in time the number of nodes added to the Scene does impact performance, but this is a moving target as each release of JavaFX is improving on this.

However, not all of this performance degradation is due to the number of nodes as it may be due to "BindStorming". See Jim Connors blog on this and other performance related posts.

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