Is there any way of getting the Stage/Window object of an FXML loaded file from the associated class controller?
Particularly, I have a controller for a modal window and I need the Stage to close it.
Is there any way of getting the Stage/Window object of an FXML loaded file from the associated class controller?
Particularly, I have a controller for a modal window and I need the Stage to close it.
Another way is define a static getter for the Stage and Access it
Now you Can access this stage by calling
In Controller Class
I could not find an elegant solution to the problem. But I found these two alternatives:
Getting the window reference from a Node in the Scene
Passing the Window as an argument to the controller when the FXML is loaded.
And FormController must implement the setStage method.