Sebastian Sebastian - 11 days ago 6
Java Question

JavaFX: Stage vs Scene

I want to change screen from login.fxml to home.fxml. Should I change stage or change scene? I'm not sure what best practice is? Also can I use a lambda expression for the handler in the controller?

Answer

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:

  • If you plan on going forward to a different place in the flow of your program (login -> profile, for example) - change the Stage.

  • If you are in the same enviroment (login for the first time -> login after multiple wrong tries) - change the Scene.

As for lambdas: Ahhmmm... if your current Java/JavaFX version has the abillity - there is no reason not to use it.

Comments