title: Relative resource paths in Java project in IntelliJ IDEA
body: <p>I am trying to display an icon in my GUI by using a relative path, as in "display image from <code>resources/image.png</code>". I have tried a million different ways to express this, but nothing works. This makes me think it's a problem with my IntelliJ IDEA settings or project structure. I have set up the "resources" folder as a "resources folder". I don't know what else it expects me to do.</p>
  
  <p><strong>How can I load an icon from a file using a relative path in a Java project within IntelliJ IDEA?</strong></p>
  
  <p>My project structure:</p>
  
  <pre><code>src/main/java/ &lt;-- set as "sources" in IntelliJ
  src/main/java/ui/ &lt;-- contains classes for my GUI
  src/main/resources/ &lt;-- set as "resources" in IntelliJ. Contains images.
  </code></pre>
  
  <p>Edit: Able to use relative path to confirm that file is found, not able to load it as icon.</p>
  
  <pre><code>String path = "src/main/resources/image.png";
  System.out.println(new File(path).exists()); &lt;-- true
  </code></pre>