0

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

kleopatra
  • 51,061
  • 28
  • 99
  • 211

1 Answers1

1

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

enter image description here

butterfly
  • 56
  • 5