javajavafxfxmlscenestage

JavaFX: Best practice for navigating between UI screens


I want to change UI screens from login.fxml to home.fxml.

Should I change the Stage or the Scene? I'm not sure which is the best practice? Also, can I use a lambda expression for the handler in the controller?


Solution

  • First, let's start out with the Stage .vs. Scene issue:

    As known, the JavaFX hierarchy is based on: Stage -> Scene -> Nodes (etc).

    See here:

    enter image description here

    Practically speaking, a rule-of-thumb in my opinion is the future:

    As for lambdas: Ahhmmm... if your current Java/JavaFX version has the abillity - there is no reason not to use. For more about controller handlers in Java 8, see this great tutorial.