如何更改 javafx 警告框的图标

How to change the icon of a javafx alert box

如何在我的 javafx 应用程序中更改警告框的图标。我知道如何为我的主要 application/stage 本身做这件事,但同样的方法不适用于警报。

Example of alert in javafx

像这样?

@Override
public void start(Stage stage) {
    Alert alert = new Alert(Alert.AlertType.ERROR);
    alert.setTitle("Alert Test");
    alert.setHeaderText("Hello, world!");
    ImageView icon = new ImageView(new Image(String.valueOf(this.getClass().getResource("img/close-on.png"))));
    icon.setFitHeight(48);
    icon.setFitWidth(48);
    alert.getDialogPane().setGraphic(icon);
    alert.show();
}