Loading images from jars for Swing HTML

Viewed 9455

While this answer works to load images from Jar files for ImageIcons, I cannot seem to get the right path for images referenced in Swing HTML.

This displays an image in the Swing HTML when the resources are not bundled into a jar:

new JLabel("<html><table cellpadding=0><tr><td><img src='file:icons/folder_link.png'></td></tr><tr><td>100</td></tr></table></html>") );

Inside of the jar, the image can be successfully referenced (and displayed) into an ImageIcon:

Icon topIcon = new ImageIcon( getClass().getResource("icons/folder_link.png" ) );

However, my attempt to use the getResource technique for Swing HTML doesn't work.

String p = getClass().getResource("icons/folder_link.png" ).getPath();
new JLabel("<html><table cellpadding=0><tr><td><img src='" + p + "'></td></tr><tr><td>100</td></tr></table></html>") );

What's the secret?

4 Answers
Related