简体   繁体   中英

How to change the icon of a javafx alert box

How do I change the icon of the alert box of in my javafx application. I know how to do it for my main application/stage itself but the same method doesn't work for the alert.

Example of alert in javafx

like this?

@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();
}

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM