I wanted to know how should I set icons on javaFX stage. I have found this method, but it did not work properly.
stage.getIcons().add(new Image(iconImagePath));
stage is an instance of javafx.stage.Stage, and I have imported javafx.scene.image.Image. This is the exception which we receive:
Invalid URL: Invalid URL or resource not found
Also, there is nothing wrong with the iconImagePath, its value is "G:/test.jpg" and there is a jpg file in the G drive named test. In addition, when we use ImageIO to read the same URL we can do it easily.
This is what I've done and it work. The image is located in the root of my resource folder.
I am using JavaFX 8
Here is the working code, which is exactly what you neened:
Set Icon by statement:
Best Way:
I faced the same problem. I used Netbeans. I'm not sure if the folder structure is different for other IDEs, but I had to put the picture in /build/classes/(package that contains the JavaFX class file). This means it doesn't go into the src folder.
use
and put the image logo.png in root of your project ( at same directory where src )