Reputation: 35864
I've read several things about Scenes vs Panes / StackPanes in JavaFX. I'm just having a hard time determining if there is an "industry standard". Primarily, I'm wanting to go from Login -> Dashboard -> Other "screens". Is there a preferred / standard for this with regards to scenes vs stackpane? I understand if this question gets closed because of "opinion based" but I'm technically not looking for an opinion; I'm looking for the standard by which JavaFX Applications should be architected.
Upvotes: 0
Views: 932
Reputation: 1032
I think it really depends on the nature of your application. Ie., is it a single visible window that changes content depending on your activity (e.g., something like Windows calculator that can change mode), or an editor-like main window with tabbed panes, or a "tool" application like an image editor with a main view and separate child panes.
For your use case I would just switch out the root node property of your main Scene object. So you would have a "Dashboard" root node, and when you click/select something on the dashboard you just update the root node property with the new node to display.
Upvotes: 0
Reputation: 3281
AFAIK there's no standard coming from JavaFX core nor any set of guidelines for that matter.
Back in the Swing days we used to rely on CardPane
to attain the desired behavior. Sadly JavaFX core does not provide such container/component out of the box. One could write up a similar container based on StackPane
(the trick is to make sure children nodes in the back layers are hidden from view).
Switching scenes as you mention appears to be a popular option too, although I prefer changing the root of the scene
instead o switching the whole thing completely.
finally, building a medium to large sized JavaFX application most likely requires an application framework of some sort. Again JavaFX core delivers no support in this regard besides the very basic application lifecycle provided by the Application
class. My suggestion is to have a look at https://github.com/mhrimaz/AwesomeJavaFX#frameworks and evaluate those options depending on your specific requirements. I'm biased but I'd suggest you to have a look at http://griffon-framework.org/. In all fairness Griffon doesn't enforce a particular strategy that can answer your question, but the recent additions to its JavaFX support should make it simpler to implement a CardPane
. Perhaps that's what we'll do for the next release :-)
Upvotes: 1