title: Loading images from jars for Swing HTML
body: <p>While <a href="https://stackoverflow.com/questions/31127/java-swing-displaying-images-from-within-a-jar">this answer</a> works to load images from Jar files for <code>ImageIcons</code>, I cannot seem to get the right path for images referenced in <a href="http://download.oracle.com/javase/tutorial/uiswing/components/html.html" rel="nofollow noreferrer">Swing HTML</a>.</p>
  
  <p>This displays an image in the Swing HTML when the resources are not bundled into a jar:</p>
  
  <pre><code>new JLabel("&lt;html&gt;&lt;table cellpadding=0&gt;&lt;tr&gt;&lt;td&gt;&lt;img src='file:icons/folder_link.png'&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;100&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/html&gt;") );
  </code></pre>
  
  <p>Inside of the jar, the image can be successfully referenced (and displayed) into an <code>ImageIcon</code>:</p>
  
  <pre><code>Icon topIcon = new ImageIcon( getClass().getResource("icons/folder_link.png" ) );
  </code></pre>
  
  <p>However, my attempt to use the <code>getResource</code> technique for Swing HTML doesn't work.</p>
  
  <pre><code>String p = getClass().getResource("icons/folder_link.png" ).getPath();
  new JLabel("&lt;html&gt;&lt;table cellpadding=0&gt;&lt;tr&gt;&lt;td&gt;&lt;img src='" + p + "'&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;100&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/html&gt;") );
  </code></pre>
  
  <p>What's the secret?</p>