构建 gui 组件树的首选方法
构建应用程序 gui 组件树的首选方法是什么?
实例化所有组件并构建整个树,通过对用户事件的显示/隐藏/禁用/启用操作来控制它。
实例化所有组件并构建整个树使用基于用户事件的创建/添加/删除组件动态创建 gui。
我对 JavaFX 中的这个设计问题特别感兴趣。
What is the preferred way to build application gui components tree?
Instantiate all components and build an entire tree, controlling it with show/hide/disable/enable operations on user events.
Dynamically creating gui with create/add/remove components based on user events.
I'm especially interested with this design problem in JavaFX.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
抱歉,我对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.
答案主要取决于性能。 我已经毫无问题地构建了大约 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.