Define a relative path of image in Java FX

I'm going to answer my own question as I actually found a solution to this! My solution is to use the "file:" prefix when specifying a path. So:

Image img = new Image("file:images/portal.png");

Works perfectly when the image file is outside of my src folder!


I think you are running into issues because the Images folder is outside of the scope of your project. You could consider changing the structure of your project.

Ex:

->src
|-->main
    |--->java
          |-->(default package)
    |--->resources
          |-->images

Then you should be able to access your image with the path ./src/main/resources/images/portal.png