The documentation you linked states that stage.close()
:
Closes this Stage. This call is equivalent to hide().
As hide()
is equivalent to close()
and close()
closes the stage, then hide()
also closes the stage.
When all stages in an application are hidden (or closed if you like, because it is the same thing), the application exits. Confusing, I know, but that's just the way the JavaFX team decided to name and implement the actions.
If desired, the Platform.setImplicitExit(boolean) method can be used to switch off the default behaviour of exiting the application when the last window is closed or hidden.
Then it comes to the question, How can we hide the stage without closing it completely?
I don't think hide()
or the equivalent close()
method will close the stage "completely" as in freeing up all resources related to the window (as long as you keep a reference to the stage around somewhere). I think it just makes it so that the stage is not visible. You could probably call show()
after calling close()
and the window would likely be made visible again (I didn't try it). Though, if you were to do that, then it would be more intuitive to call hide()
rather than close()
.
My guess is that if you no longer keep any references to a stage in your application and the stage is closed or hidden, then perhaps the JVM will release all resources related to the stage whenever its algorithm decides to garbage collect those resources (again I didn't test this and it may not work that way).