1

In IntelliJ I can run:

ImageIcon icon = new ImageIcon("src/de/therealjan/tools/pictures/pic.png");

But in a runnable JAR File that won't work. I already tried "/pictures/pic.png" but that doesn't work too.

Any ideas?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
TheRealJan
  • 49
  • 1
  • 6
  • Makesure your relative path is correct. This answer to explains show to get current directory which you started the program https://stackoverflow.com/a/7603444/1431184. – printfmyname Feb 14 '20 at 17:51

1 Answers1

1

you should add the image in your classpath or a directory in your classpath and then load your image like this:

ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
URL resource = classLoader.getResource("src/de/therealjan/tools/pictures/pic.png");
ImageIcon icon = new ImageIcon(resource);
saeed foroughi
  • 1,662
  • 1
  • 13
  • 25