Bambino
Bambino

Reputation: 415

Alerts in JavaFX – Icons don’t show up after exporting jar

I’ve been trying to develop an application using Alerts, but after exporting the jar, the icon that should be displayed in the dialog, is gone:

confirmation without icon

When I start from Eclipse, the icon is shown:

enter image description here

What am I doing wrong? The code:

public class Main extends Application{
    @Override
    public void start(Stage primaryStage){
        Alert alert = new Alert(AlertType.CONFIRMATION);
        alert.show();
    } 

    public static void main(String[] args){
        launch(args);
    }
}

Edit: When starting from the command line, the following error is printed:

com.sun.javafx.css.StyleManager getCachedImage

WARNING: Error loading image: rsrc:dialog-confirm.png

I can’t figure out, why the image is (probably) missing.

Upvotes: 3

Views: 1541

Answers (1)

Bambino
Bambino

Reputation: 415

I used to export via File → Export → Java → Runnable JAR file. As jewelsea already wrote, the way of exporting it is important. Oracles documentation says, I should use Ant Tasks. After reproducing it with Eclipse, as described here, it worked.

I wasn't able to find a good explanation why this approach is necessary though.

Upvotes: 1

Related Questions