I have created a JavaFX application that contains two windows. The first window is open by default and has a button that when clicked is supposed to open the second window. I am trying to get the 2nd window stage into my Controller class so I can use the following:
public void showSubWindow() {
anotherStage.show();
}
I managed to get the PRIMARY stage (i.e) the first window into my controller class using
@FXML GridPane pane;
Stage stage = (Stage) pane.getScene().getWindow();
But when I try to use this same method to get my second window, I get a null pointer exception on this line
Stage stage = (Stage) panetwo.getScene().getWindow();
How do I get the @FXML take elements from the 2nd FXML file in this particular case and not the first?