3

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.

Bambino
  • 405
  • 4
  • 15
  • You also have to export the images that you use in your application, for example by using a separate package below your src-folder. You also can manipulate your buildpath. See here: http://stackoverflow.com/questions/25635636/eclipse-exported-runnable-jar-not-showing-images – Supahupe May 23 '16 at 15:19
  • Exporting standard JavaFX alert images with the application jar file shouldn't be necessary Supahupe. The standard JavaFX alert images ship with the Java runtime environment (Oracle JRE 8u40+). – jewelsea May 23 '16 at 20:43
  • 1
    "after exporting the jar" <= How do you export the jar? Do you use e(fx)clipse tooling? Do you (mistakenly) try to include jfxrt.jar as a bundled resource with your jar distribution? Any idea where the "rsrc:" string (which I've never seen before) in your error message comes from? Do you have some kind of OSGi application or weird, custom class-loading solution? – jewelsea May 23 '16 at 20:45

1 Answers1

1

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.

Bambino
  • 405
  • 4
  • 15