I am making an application which uses a settings menu, which i have implemented using a different stage from the main stage of the application. It is shown on a button click, and i was wondering if javafx offers a way to make the stage appear in the center of the screen by default, for me it appears in the top left. It seems like I'm missing something, because this sort of thing happens with alert dialogues for other applications, but the Dialog (or Alert) class is not ideal, as my goal doesn't really fit into a single input, like what might be seen in a dialog box.
Relevant Code:
Button settings = new Button();
Image image = new Image(getClass().getResourceAsStream("gear.png"));
settings.setGraphic(new ImageView(image));
settings.setFocusTraversable(false);
grid.add(settings, 1, 2);
settings.setOnAction(e -> {
Stage settingsStage = new Stage();
settingsStage.initModality(Modality.APPLICATION_MODAL);
//Neither centerOnScreen() or the setX, setY lines change where the stage appears
//setY and setX work themselves out if they do not rely on stage
//settingsStage.centerOnScreen();
//settingsStage.setX(stage.getX() + stage.getWidth() / 2 - settingsStage.getWidth() / 2);
//settingsStage.setY(stage.getY() + stage.getHeight() / 2 - settingsStage.getHeight() / 2);
settingsStage.show();
});
For reference, i am using javafx 8 on a mac