image files (.gif) in a jar
I'm using eclipse to create a program that uses imageicons on buttons
I can get the code to execute and display properly within eclipse, but when i export they either don't appear within the program or the program doesn't run. Can anyone provide some insight as to why this is happening?
[303 byte] By [
YODA0340a] at [2007-11-27 9:48:21]

# 1
> but when i export they either don't appear within the program or the program doesn't run.
Well these are two very different situations. I'll address the scenerio where the images don't appear in the program.
If the images appear in the IDE but not outside of it, it may be that the images have not been included in the jar file. Extract the jar to verify the images are there.jar -xvf MyJarFile.jar
Then check to see what code you are using to access the images that have been jarred. Something like URL url = getClass().getResource("/images/foo.png");
Without knowing your code it's hard to say what the problem is.
# 2
This is the method I use to gather the image (it's pretty much copy and paste from the java tutorial):
protected static ImageIcon createImageIcon(final String path) {
try{
final java.net.URL imgURL = builderWindow.class.getResource(path);
return new ImageIcon(imgURL);
}catch(Exception e){
return null;
}
}
And this would be an example call:
button.setIcon(createImageIcon("images/rightArrow.gif"));
This works from within eclipse, but when i export as a jar, the images do not appear on the button.
# 3
I don't work with Eclipse so I don't know how Eclipse bundles resources like images within jar files. So when you extracted the jar file did you see the folder called images and the rightArrow.gif inside the folder? Assuming the jar file is completely outside of Eclipse, and extracting it from a DOS prompt or bash shell....
Message was edited by:
nantucket
# 5
> And this would be an example call:
> button.setIcon(createImageIcon("images/rightArro
> w.gif"));
>
> This works from within eclipse, but when i export as
> a jar, the images do not appear on the button.
Ah. Note the absence of the path symbol "/".....
You must specify that the images directory is, presumably, at the root of the jar file. Therefore use...
button.setIcon(createImageIcon("/images/rightArrow.gif"));
And note the presence of the "/" in front of the directory name "images"
btw - thanks
Message was edited by:
nantucket