When a dialog is created using, for instance, Alert#showAndWait() it has an empty icon in the title. it should have the same icon as the application that it is running from. Here is an example code:
public class DialogDemo extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Image image = new Image("icon.png");
primaryStage.getIcons().add(image);
Button button = new Button("Show Dialog");
button.setOnAction(event -> {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.initOwner(primaryStage);
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 {
Image image = new Image("icon.png");
primaryStage.getIcons().add(image);
Button button = new Button("Show Dialog");
button.setOnAction(event -> {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.initOwner(primaryStage);
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();
}
}