Given your previous question, I imagine that by "attach" you mean something like what the File Chooser does (when there is a parent, the File Chooser will follow it around).
The first thing you need is the "main window", which you can get via
Window ownerWindow = ((Node) event.getTarget()).getScene().getWindow();
The next thing is to actually load your new stage.
Stage stage = new Stage();
stage.initModality(Modality.APPLICATION_MODAL);
stage.initOwner(ownerWindow);
Parent root = FXMLLoader.load(getClass().getResource("/gui/GUpdater-progress.fxml"));
Scene scene = new Scene(root, 600, 400);
stage.setTitle("GUpdater");
stage.setScene(scene);
stage.show();
The key is the stage.initOwner(ownerWindow)
part. This new stage you are creating is "owned by" the original window, which is ownerWindow
.
In addition, if you want to achieve a feel more like the File Chooser's, you should use
stage.initStyle(StageStyle.UNDECORATED);
Before setScene()
is called. This will remove the border.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…