Re: Giving an application a window icon in a sensible way
- From: dagon@xxxxxxxxx (Mark Rafn)
- Date: Sun, 19 Nov 2006 21:13:04 -0800
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/>
.
- Follow-Ups:
- References:
- Giving an application a window icon in a sensible way
- From: Twisted
- Re: Giving an application a window icon in a sensible way
- From: Mark Rafn
- Re: Giving an application a window icon in a sensible way
- From: Twisted
- Giving an application a window icon in a sensible way
- Prev by Date: Re: Giving an application a window icon in a sensible way
- Next by Date: Keeping multiple two dimensional arrays - recursive method
- Previous by thread: Re: Giving an application a window icon in a sensible way
- Next by thread: Re: Giving an application a window icon in a sensible way
- Index(es):