aspose file tools*
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
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Having issue accessing images inside jar " Watch "Having issue accessing images inside jar " New topic
Author

Having issue accessing images inside jar

Rite Sara
Ranch Hand

Joined: Feb 13, 2010
Posts: 56
Hi,

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());
this.jPanel1.add(panel);

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());
this.jPanel1.add(panel);

 
Don't get me started about those stupid light bulbs.
 
subject: Having issue accessing images inside jar