Displaying Images



Hey, All!

I'm writing a rather complex GUI program using Java 6 and NetBeans IDE
5.5. My project is coming along sharply, but I'm getting hung up on the
simplest of concepts.

I've read the tutorials, looked at the source code to them, searched the
net, read tons of source code and can't seem to make it work in my
project. What I'm talking about is simply displaying a picture on an
element of my forms.

For example, displaying a graphic on my About screen that is related to
the program. Or, showing screenshots that are previews of the various
themes for the Metal look and feel that I have already made.

I've got these images stored under my project source tree in a folder
called resources, but as far as I can tell, the only way these images get
compiled into the resources folder in the JAR are if they are actually
loaded at design time in the IDE.

I don't mind if I have to add these images to the JAR after I've compiled,
if I'm able to load them at runtime. I've tried loading them using a
path-like string, but that doesn't work. I've tried loading them using
getResource() and that doesn't seem to work as well.

I've been pouring over the JavaDocs for the APIs and I'm just getting more
and more confused. I've seen constructors that require an Icon object,
but when I look up that Icon object, it seems to want an Image object for
its constructor. And when I looked up Image, it didn't want a string
either. I've tried building the path using an URL object and can't seem
to get any of this to work.

If someone could please post a code snippet that shows how to load an
image file from the resources folder of the JAR file into a LayeredPane
object (or another object that may work better), I would greatly appreciate
it. It's driving me crazy that the simplest thing (nice-to-have, but *not*
needed) is bogging me down.

Thank you all for your time in reading this very long-winded message. I
hope to hear from some of you in the near future. Have a great day.

Cheers,

Sean
.



Relevant Pages

  • Re: images and jar file craziness
    ... And I can get this app to run from the jar (depending on what ... but I can't get the images to work. ... I understood from you earlier post you could not get a jar to execute ... It's not that you were using a relative path, ...
    (comp.lang.java.help)
  • Re: Anyone ever done this with images in a jar
    ... am callling "across directories" within the jar, ... >> What do people do when they must access images within a jar? ... > image files and 100 subdirectories in each directory. ... > If you don't have that limit then you can use a larger modulus. ...
    (comp.lang.java.programmer)
  • Re: images and jar file craziness
    ... several apps and gotten them to work in a jar, ... And I can get this app to run from the jar (depending on what ... but I can't get the images to work. ... I understood from you earlier post you could not get a jar to execute ...
    (comp.lang.java.help)
  • Re: images and jar file craziness
    ... And I can get this app to run from the jar (depending on what ... but I can't get the images to work. ... It's not that you were using a relative path, ... on the package structure of the class definitions. ...
    (comp.lang.java.help)
  • Re: JEditorPane shows IMG tags broken when image file is in applications jar
    ... > broken-image icon. ... > able to refer to images in a jar from HTML documents in a jar, ... > images used for other purposes work well. ...
    (comp.lang.java.programmer)