Display picture stored in jar file
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Alvaro_Ulate
Posted On:   Wednesday, March 24, 2004 08:25 AM

I am trying to display one image in JLabel, my problem is, that image is stored in jar file and I don't know how extract it with my java code. the jar structure is: + jarfile + Package1 + image.gif + more packages ... I am using this code to display it lblFoto= new JLabel(); ImageIcon f = new ImageIcon("image.gif"); lblFoto.setIcon(f); and it work fine if I in the absolute address of image's copy in hard disk but I need to use the image in jar file I tried with "image.gif","Package1.image.gif" and "Package1/image.gif" but it not works!! Please if somebody knows how do it, tel   More>>

I am trying to display one image in JLabel, my problem is, that image is stored in jar file and I don't know how extract it with my java code.

the jar structure is:
+ jarfile
+ Package1
+ image.gif
+ more packages ...

I am using this code to display it

lblFoto= new JLabel();
ImageIcon f = new ImageIcon("image.gif");
lblFoto.setIcon(f);

and it work fine if I in the absolute address of image's copy in hard disk

but I need to use the image in jar file

I tried with "image.gif","Package1.image.gif" and "Package1/image.gif"

but it not works!!

Please if somebody knows how do it, tell me

Thank you

I am sorry my poor English

   <<Less

Re: Display picture stored in jar file

Posted By:   manu_kaushal  
Posted On:   Sunday, March 28, 2004 09:43 AM

Use method :
new ImageIcon(getClass().getResource("/Package1/image.gif"));
Remember to set proper classpaths.
About | Sitemap | Contact