JavaFX: How to get stage from controller during initialization?
I want to handle stage events (i.e. hiding) from my controller class. So all I have to do is to add a listener via ((Stage)myPane.getScene().getWindow()).setOn*whatIwant*(...); but the problem is that initialization starts right after Parent root = FXMLLoader.load(getClass().getResource("MyGui.fxml")); and before Scene scene = new Scene(root); stage.setScene(scene); thus .getScene() returns null. The only workaround I found by myself is to add a listener to myPane.sceneProperty(), and when it becomes not null I get scene, add to it's .windowProperty() my !goddamn! listener handling which I