I am following the turorial below: (using javafx 20.0.1 and open jdk 20.0.1 --> intellij IDE and Maven build tool)
JavaFX Tutorial Part 4: CSS Styling
At the last part of the tutorial I need to set icon to the scene.
I have followed what is written on the instruction but the image deos not show.
Here is my file structure:
Here is the code:
this.primaryStage.getIcons().add(new Image("file:images/86957_address_book_icon.png"));
I have noticed that, in the constructor before the location of the image (images/86957_address_book_icon.png) the following was written:
file:
I am new to java and javafx in general. Not sure what is this.
Tried without file: and the following error was thrown:
Exception in Application start method
...
...
Caused by: java.lang.IllegalArgumentException: Invalid URL: Invalid URL or resource not found
...
...
I have tried the following location strings:
added /
--> "file:/images/86957_address_book_icon.png"
full path --> "file:com/adnan/addressapp/images/86957_address_book_icon.png"
absolute path --> ONLY THEN IT WORKED
But this is not the solution I want or need.
Could you please help?