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 Having issue accessing images inside jar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Having issue accessing images inside jar " Watch "Having issue accessing images inside jar " New topic

Having issue accessing images inside jar

Rite Sara
Ranch Hand

Joined: Feb 13, 2010
Posts: 56

I have created one swings application using Eclipse IDE. I want to use it by creating a jar file.
The app has many images used in the panels as well as tables. These images are displayed properly when I run my project in eclipse.
But when I make a jar these images are not displayed.

Here is the way I am using images :

My project folder is on desktop having following path and I am storing images inside Create 2\images .. where Create 2 is the name of my project folder or project.

C:\Documents and Settings\25466\Desktop\Create 2\images

Then I am referring these images inside code using following path :

ImagePanel panel = new ImagePanel(new ImageIcon("images/banner.PNG").getImage());

Please let me know what is going wrong ..where I can place the images folder so that they are displayed in the jar too...
Rite Sara
Ranch Hand

Joined: Feb 13, 2010
Posts: 56
I am able to resolve this issue ... I used following code ...

URL imageURL = getClass().getClassLoader().getResource("images/banner.PNG");
ImagePanel panel = new ImagePanel(new ImageIcon(imageURL).getImage());

I agree. Here's the link:
subject: Having issue accessing images inside jar
Similar Threads
Image doesnot get displayed in an Eclipse OSGi Project
Error : class not found exception : com.mysql.jdbc.driver in eclipse Tool
How to insert .gif image inside a panel
Problem Updating a JButton
File Creation In a webapp