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



Mark Rafn wrote:
Twisted <twisted0n3@xxxxxxxxx> wrote:
I want to give a Java application a window icon in a manner that is
independent of how it is installed, etc.
The trick is obtaining an Image object for myJFrame.setIconImage().
Loading it from a URL means it won't work without a working network
connection, and I need to host the image somewhere.

Not at all. A URL doesn't always mean http. It could be a file URL, or a
resource URL inside your jarfile.

File URL and jar I was considering separately.

URL imgURL = getClass().getClassLoader().getResource("img/path");

Works if the image is in a jarfile OR a directory on the classpath.

Hrm.

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 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. Of course, this turned out not to be a
standard library class, and tracking it down posed its own challenge
(during which time Firefox crashed for the second time today -- it hit
a crapplet on a page somewhere and died the number. It actually
tottered along sort-of-working until I quit it, but wouldn't load
anything -- and after being quit I couldn't start a new instance until
I terminated a bunch of firefox-related processes that were idling in
the task manager that didn't have any UI or cpu activity!).

Naturally, the XImageSource class had dependencies to track down as
well.

Naturally, one of those dependencies had a bug -- XpmParser. It had

colors = new int[charsPerPixel*2];

where it appeared to need

colors = new int[(charsPerPixel == 2)?65536:256];

since it actually multiplies one char by 256 and adds a second in the
latter case, and was throwing ArrayOutOfBoundsExceptions like they were
going out of style.

Naturally, the author of those classes included a copyright notice and
will probably sue me for copyright infringement for fixing their bug
without permission, too, now that I've copped to this heinous act in a
public newsgroup posting.

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.

Thanks anyway. :)

.



Relevant Pages

  • Re: identifiers and modules
    ... Perhaps such a restriction would make sense in PLT's "Beginning Student" language. ... a procedure can be inspected for its external dependencies merely by ... examining all names in the enclosing scopes. ... I disagree - an indentation bug is also a bug, just like a comment bug is a bug: ...
    (comp.lang.scheme)
  • Re: Realbasic 2005r2 Bugs (Ive personally found so far)
    ... I'm guessing from your replies you have very little experience on computers. ... Number 1) call it what you want but an unsupported issue is not a bug, ... >> Number 2 Wait longer after a save before you quit the program. ... If you want to get your taskbar back because ...
    (comp.lang.basic.realbasic)
  • Re: Just random fixes with QC reports...
    ... > Adhering to best practices does not bestow omniscience. ... and thus there are dependencies. ... > and nature of a bug, a fix to it can have consequences on the dependent ...
    (borland.public.delphi.non-technical)
  • Re: Help! WScript application error!
    ... > I found a bug in my script. ... Due to a design error, it calls Quit() ... I *suppose* that the script logic error you found could end ...
    (microsoft.public.scripting.vbscript)
  • Re: Packages: required vs recommended vs suggested
    ... >> Then perhaps they're actually dependencies? ... is unusable (see the output of apt-cache search libsasl2). ... required dependency in case someone has other sasl2-pam plugins ... going) to see what he thought about this before I file a bug. ...
    (Debian-User)