views:

89

answers:

2

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.

A: 

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.

Scott Langham
A: 

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.

JimClarke