Determine relative path of an image in Java fx
I know this has been asked many times and I have searched all over the world for a solution to this probably simple problem. I am trying to follow the simple javaFX tutorials on the Oracle website. I can define an image this way:
Image img = new Image("images/portal.png", 50, 50, true, true);
This works when the image is in a folder inside the "src" folder, but I am trying to find it to find the image when I have a folder with images outside the "src" folder, for example:
http://puu.sh/drF7K/bbf1a047aa.png
How can I make this work? All I get are errors saying "Invalid URL or resource not found". I tried using an absolute path, tried putting ".." on it, tried "HS-Graph / images / portal.png" and everything in between :( Thanks!
source to share
I think you are in trouble because the Pictures folder is outside the scope of your project. You may consider changing the structure of your project.
Example:
->src
|-->main
|--->java
|-->(default package)
|--->resources
|-->images
Then you should be able to access your image using the path. / Src / main / resources / images / portal.png
source to share