Re: Giving an application a window icon in a sensible way



Twisted <twisted0n3@xxxxxxxxx> wrote:
Loading it from a URL means it won't work without a working network
connection, and I need to host the image somewhere.

Mark Rafn wrote:
Not at all. A URL doesn't always mean http. It could be a file URL, or a
resource URL inside your jarfile.
URL imgURL = getClass().getClassLoader().getResource("img/path");
Works if the image is in a jarfile OR a directory on the classpath.

Twisted <twisted0n3@xxxxxxxxx> wrote:
Anyway I found something interesting. My google-fu isn't as weak as I
thought -- I was eventually able to dredge up a way to encode icons
into a class file.

It doesn't need to be a class file for the classloader to find it as a
resource.

It involved exporting the file from photoshop as an XPM, pasting most
of the result into the declaration of a string array, and feeding it to
a class named XImageSource.
....
Naturally, the XImageSource class had dependencies to track down as
well.
....
But it actually works, and the source code is completely
self-contained, without requiring any extra files besides the .java
files. Which is what I was hoping to accomplish.

Wouldn't it be MUCH easier to put gif/jpg/png files directly into the jar,
then let the classloader find them using getResource or getResourceAsStream?
--
Mark Rafn dagon@xxxxxxxxx <http://www.dagon.net/>
.