File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Add Image on to JFrame in jar file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Add Image on to JFrame in jar file" Watch "Add Image on to JFrame in jar file" New topic

Add Image on to JFrame in jar file

dushantha Rathnayake
Ranch Hand

Joined: Feb 27, 2010
Posts: 103

I have a jar file. After run it's "source" code I can see the JFrames with images. But if I run it's jar file their are no any image on jframes. my java file and other images are in same directory. how can I make a jar file with this all files. because if i give this jar file and images to other person he can edit the images that he want. So haw can I build a jar file that hold all images and class files? Please help me.

Thank you.
Rob Spoor

Joined: Oct 27, 2005
Posts: 20276

Use Class.getResource to get a URL to the resource (inside the JAR file), then use that resource to create the ImageIcon.

How To Ask Questions How To Answer Questions
muntago Richard
Ranch Hand

Joined: Nov 13, 2010
Posts: 82
I want to understand your question, You said that when you run the applications that it was perfect but now you wish to make it executable such eg example.jar and to that effect, the image is not displaying, is that your question.
I agree. Here's the link:
subject: Add Image on to JFrame in jar file
It's not a secret anymore!