I have an application which opens absolutely fine, but am having trouble setting an icon for it. The icon I give the path to is there, and changing to another imagine in that directory shows the icon 9/10 times, but this image never shows. There is always a question mark in it's place. So even on another file, which I know will work (ie. isn't corrupted), how come it only shows so rarely?
Below is the code of MyApplication.java
package MyApp;
import MyApp.Variables.Constants;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("Forms/FormMain.fxml"));
primaryStage.getIcons().add(new Image(getClass().getResourceAsStream("/img/appicon.png")));
primaryStage.setTitle("MyApp " + Constants.VERSION_NAME + " (" + Constants.RELEASE_ID + ")");
primaryStage.setScene(new Scene(root, 1000, 800));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Below is the project directory structure relating /img/ to Main.java:
I have tried all the solutions here but nothing fixed my issue.
Running on Ubuntu 16.04, intelliJ IDEA for the IDE, though the problem persists with an exported JAR file.