I am trying to set an icon to my JavaFX 8 Application, but the icon is not shown. Trying to understand the problem I create a very simple application with one Main class. Here is its code:
package application;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
StageStyle style = primaryStage.getStyle();
// style == StageStile.DECORATED
try {
primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("phog16.png"))); // iconSize == 16x16px
primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("phog22.png"))); // iconSize == 22x22px
primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("phog24.png"))); // ...
primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("phog32.png")));
primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("phog48.png")));
primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("phog16.png")));
primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("phog64.png")));
primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("phog128.png")));
primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("phog256.png")));
primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("phog512.png")));
int size = primaryStage.getIcons().size();
// size == 10
BorderPane root = new BorderPane();
Scene scene = new Scene(root,400,400);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.setTitle("Application Icon");
primaryStage.show();
}
catch(Exception ex) {
ex.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
As application output shows there is no application icon: application output
My environment: Debian 9.1 (Stretch) 64bit Gnome; eclipse-SDK-4.7-linux-gtk-x86_64; jdk-8u144-linux-x64
What am I doing wrong?