i have created executable jar file for my program pedit.java as follows

jar cvfm pedit.jar manifest.txt images *.class splash.gif

where images is a directory where the icons for toolbar are there,as my program is a editor...
my problem is that when i run the jar file the application is loaded succesfully but icons on the toolbar are not visible....

can anyone suggest what should i do??

How are you loading the images? Hopefully with getResource (or getResourceAsStream) and not with File (or FileInputStream, etc) as the items in a jarfile are not Files, at least until the jarfile is unpacked.

i am loading the images in the code as

JButton bcut = new JButton("images\cut.gif");

Um, that would create a Button with the text "images\cut.gif", not an Icon.

sry i have created an button as

JButton bcut = new JButton(images\cut.gif);

I don't believe that would work at all since you cannot have a "\" in a variable name, AFAIK.

hello sry again,i hav created a image button with icon,my jar file is working in the directory in which my program is there but not in other directories??
please see this

Show me the code where you are defining and creating the Icons. That is probably where the problem is.

this is the code i used to create a button on the toolbar

ImageIcon cut = new ImageIcon("images/cut.gif");
    final JButton bcut = new JButton(cut);

this is the code i used to create a button on the toolbar

ImageIcon cut = new ImageIcon("images/cut.gif");
    final JButton bcut = new JButton(cut);

Yep, and that is using files, you need to use streams change

ImageIcon cut = new ImageIcon("images/cut.gif");

to

ImageIcon cut = new ImageIcon(ImageIO.read(getClass().getResourceAsStream("/images/cut.gif"));

assuming "images" is a "top-level directory" within the jarfile.

Edit: But that will leave the InputStream open so this is better

InputStream is = getClass().getResourceAsStream("/images/cut.gif");
ImageIcon cut = new ImageIcon(ImageIO.read(is));
is.close();

to masijade: i have tried waht u hav said but it is not working an exception is been caught

InputStream is = getClass().getResourceAsStream("cut.gif");
ImageIcon cut = new ImageIcon(ImageIO.read(is));
final JButton bcut = new JButton(cut);

i used the above code by placing cut.gif file in the same directory of the program..

In that form "cut.gif" needs to be located in the same directory as the class containing this call, inside the jarfile, of course.

No idea if that is what you meant by "program".

Seeing what execption is thrown, might help. The complete stacktrace, BTW. And don't forget to close the stream (preferrably in a finally block).

yeah the file is there in the same directory of class containing this call.when i run that class an exception is caught and it is quitting

i used this code

ImageIcon find = new ImageIcon(getClass().getResource("images/find.gif"));
    final JButton bfind = new JButton(find);

and now my problem is solved and thanks for helping me

Then the image was not in the same place as the class file, but rather one directory below the class file.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.