Dialogs on Windows aren't shown in the center of the screen. The native behavior on Windows is to open dialogs in the middle.
public class DialogDemo extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Button button = new Button("Show Dialog");
button.setOnAction(event -> {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.initOwner(primaryStage);
// workaround
// alert.getDialogPane().getScene().getWindow().centerOnScreen();
alert.setContentText("Message");
alert.setHeaderText("Header");
alert.setTitle("Title");
alert.showAndWait();
});
BorderPane root = new BorderPane();
root.setCenter(button);
Scene scene = new Scene(root, 300, 300);
primaryStage.setScene(scene);
primaryStage.show();
}
}
public class DialogDemo extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Button button = new Button("Show Dialog");
button.setOnAction(event -> {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.initOwner(primaryStage);
// workaround
// alert.getDialogPane().getScene().getWindow().centerOnScreen();
alert.setContentText("Message");
alert.setHeaderText("Header");
alert.setTitle("Title");
alert.showAndWait();
});
BorderPane root = new BorderPane();
root.setCenter(button);
Scene scene = new Scene(root, 300, 300);
primaryStage.setScene(scene);
primaryStage.show();
}
}