I am creating an application in JavaFx, In which I want to do that if any child stage is getting opened then it should be opened in center of parent stage.
I am trying to do this using mystage.centerOnScreen()
but it'll assign the child stage to center of screen, not the center of parent stage.
How can I assign the child stage to center of parent stage?
private void show(Stage parentStage) {
mystage.initOwner(parentStage);
mystage.initModality(Modality.WINDOW_MODAL);
mystage.centerOnScreen();
mystage.initStyle(StageStyle.UTILITY);
mystage.show();
}
When you don't determine a size for the childStage, you have to listen for width and height changes as width and height is still NaN when onShown is called.
You can use the parent stage's X/Y/width/height properties to do that. Rather than using
Stage#centerOnScreen
, you could do the following: