title: Add images to jar
body: <p>I want to set icon to my JFrame. I do the following:</p>
  
  <pre><code>Image icon = Toolkit.getDefaultToolkit().getImage("src/images/icon.jpg");
  this.setIconImage(icon);
  </code></pre>
  
  <p>It works fine when I run this code from netbeans, but when I try to run this code from jar file, images are not shown in my JFrame. I have tried to load images as resources:</p>
  
  <pre><code>this.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/src/images/icon.jpg")));
  </code></pre>
  
  <p>but when I run this code it fails with <code>NullPointerException</code></p>
  
  <pre><code> Uncaught error fetching image:
  java.lang.NullPointerException
          at sun.awt.image.URLImageSource.getConnection(URLImageSource.java:99)
          at sun.awt.image.URLImageSource.getDecoder(URLImageSource.java:113)
          at sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:240)
          at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:172)
          at sun.awt.image.ImageFetcher.run(ImageFetcher.java:136)
  </code></pre>
  
  <p>How can I do this work?</p>
  
  <p><strong>edit:</strong>
  Thanks to all,
  the problem  was solved by specifying image as</p>
  
  <pre><code>Toolkit.getDefaultToolkit().getImage(getClass().getClassLoader().getResource("images/icon.JPG"))
  </code></pre>
  
  <p>As for it seems rather weird, and would be better if it was like</p>
  
  <pre><code>this.setIconImage(new ImageIcon(pathToIcon).getImage());
  </code></pre>