r/JavaFX • • Aug 06 '25

Help there is any standarized way of navigating between scenes

Hello everyone I'm basically creating a desktop app that have multiple scenes, but right now I'm doing patchwork for managing the state of which scene is showing, ugly code that make harder to do dependency injection.

So what do you recommend me? there is any tool that permit and easy way of navigating between scenes and inject the dependencies, I'm using Guice for DI.

9 Upvotes

15 comments sorted by

View all comments

5

u/emberko Aug 07 '25

JavaFX is not a framework, it's a UI toolkit. You should split your goal into actionable tasks. It basically consists of the following:

  • How to maintain the state. I recommend familiarizing yourself with FSM (finite state machines).

  • How to update the UI. You can use StackPane as suggested, or any Pane, actually. It generally boils down to mainView.getChildren().setAll(currentlyActiveView).

  • How to build an app architecture that is not PITA. This addresses how to integrate dependency injection. I recommend taking a look at MVVM or MVCI. For a DI container, check Avaje Inject.

1

u/Dense_Age_1795 Aug 07 '25

the main problem with mvvmfx is that it doesn't have support to java 11 modules, and that made incompatible with the most modern version of javafx, anyways I will look the MVCI approach, thanks a lot.

1

u/sedj601 Aug 07 '25

I don't have anything against MVCI. I just want to put out there that I like https://stackoverflow.com/questions/32342864/applying-mvc-with-javafx. Both are great IMO.

→ More replies (1)