>> If the image files are in the same package as the class accessing them, then do this.
>>
>> ImageIcon image = new ImageIcon(this.getClass().getResource("test.png"));
>
> I've found the solution you recommend in Sun's Java forums as well.
Where? URL?
I doubt it was stated like that, since that provides little
more information, than the way that you were doing it.
In fact, 'under the covers' that is exactly what the String
constructor is doing..
<http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/ImageIcon.html#ImageIcon(jav
a.lang.String)>
The only advantage to doing it that way comes if you
split it up further.
URL imageURL = this.getClass().getResource(pathString);
System.out.println( "imageURL: " + imageURL);
ImageIcon image = new ImageIcon( imageURL );
WSe are all *expecting* imageURL to be 'null', though
if it prints an URL - that is entirely another matter!
> I'll try it tomorrow and post the results here. Any idea why packaging
> thngs into a jar requires this particular bit of coding?
Using getResource() consistently is the best way to get your
resources, most of the methods and constructors that take strings
or URL's, actually use getResource behind the scenes to convert
the string to an URL.

Signature
Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
See You On Some Other Channel
Mark - 15 Jul 2005 11:48 GMT
>>>If the image files are in the same package as the class accessing them, then do this.
>>>
[quoted text clipped - 28 lines]
> or URL's, actually use getResource behind the scenes to convert
> the string to an URL.
Andrew and Tom...
Thanks to you both. The solution suggested by...
ImageIcon image =
new ImageIcon(this.getClass().getResource("test.png"));
...does the trick. (No need to put my classes into packages.)
The Sun Java forum entries that seemed to suggest something similar were...
http://forum.java.sun.com/thread.jspa?threadID=643547&tstart=0
http://forum.java.sun.com/thread.jspa?threadID=641056&tstart=30
http://forum.java.sun.com/thread.jspa?threadID=621960&tstart=165
http://forum.java.sun.com/thread.jspa?threadID=610633&tstart=195
Regards,
Mark
Tom N - 15 Jul 2005 15:13 GMT
>>> If the image files are in the same package as the class accessing
>>> them, then do this.
[quoted text clipped - 5 lines]
>
> Where? URL?
Sun's How to Use Icons tutorial says essentially the same thing.
http://java.sun.com/docs/books/tutorial/uiswing/misc/icon.html
> I doubt it was stated like that, since that provides little
> more information, than the way that you were doing it.
[quoted text clipped - 13 lines]
> WSe are all *expecting* imageURL to be 'null', though
> if it prints an URL - that is entirely another matter!
Huh? URL is obviously not null or there's not going to be any image icon.
URL will be something like file:/C:/temp/x2.png