Question

It is a classic question but even with a stack overflow search I did not found an answer. The problem concerns the retrieval of an image with a relative path.

With an absolute path it works, and here you can see the code using the statement getClass.getResource(filename), with the directory structure of my project. It's the same I think in Java.

Maven structure:

src
 - main
   - java
     - lanceur.scala
   - resources
     - down_arrow.png

Code:

btn_bas.icon= new ImagaeIcon(Fenetre.getClass()
                    .getResource("../resources/down_arrow.png"))
Was it helpful?

Solution

The root of your classpath is both the java and resources directory. In a JAR there is nothing below them.

Try "/down_arrow.png".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top