Reputation: 10815
I just came from Is There any Way to Create A Child Window That Has the Same Properties as the Parent? and I tried to call stage.initOwner(((Node) event.getSource()).getScene().getWindow());
but it didn't work and I got an exception. I don't think that I'm using this correctly. How should I attempt to call this from the onAction method?
ORIGINAL CODE BLOCK:
@FXML
private void onNewClanCreation(ActionEvent event) throws IOException {
Parent root = FXMLLoader.load(getClass().getResource("ClanCreationPanel.fxml"));
Stage stage = new Stage();
stage.setScene(new Scene(root));
stage.initOwner(((Node) event.getSource()).getScene().getWindow());
stage.setResizable(false);
stage.setTitle("New Clan Creation");
stage.show();
}
Exception:
`Caused by: java.lang.ClassCastException: javafx.scene.control.MenuItem cannot be cast to javafx.scene.Node at com.gmail.physicistsarah.program.core.ControlPanelController.onNewClanCreation(ControlPanelController.java:65)
... 54 more`
EDIT: Added stage.initOwner
Upvotes: 0
Views: 1649
Reputation: 10815
This worked:
stage.initOwner(this.nameLabel.getScene().getWindow());
Thanks @ItachiUchiha
Upvotes: 2