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.
Asked
Active
Viewed 531 times
0
-
Just to be sure... you want to change alert's window icon or icon displayed next to message? – Wortig Mar 28 '21 at 12:33
-
@Wortig alert window's icon. – E014 Alok Rajpurohit Mar 28 '21 at 12:39
-
This should answer your question altough it is for javafx version 8. https://stackoverflow.com/questions/27976345/how-do-you-set-the-icon-of-a-dialog-control-java-fx-java-8 – Wortig Mar 28 '21 at 12:42
-
please don't add tags that are not needed - it's nothing version specific :) – kleopatra Mar 28 '21 at 13:06
-
@kleopatra sorry. I will take care about that from next time. – E014 Alok Rajpurohit Mar 31 '21 at 06:23
1 Answers
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();
}

butterfly
- 56
- 5