aspose file tools*
The moose likes Java in General and the fly likes How to load an image from java program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to load an image from java program" Watch "How to load an image from java program" New topic
Author

How to load an image from java program

Radha MahaLakshmi
Ranch Hand

Joined: Mar 28, 2003
Posts: 45
Hi All
I am trying to load an image to display in JLabel.
I am doing it in the following way.
ImageIcon icon = ClassLoader.getSystemResource("images/logo.gif");
JLabel title = new JLabel(" Commingled Funds Trade Entry ",icon,JLABEL.Left)
my gif file is in c:/images/logo.gif;
i am running this from c:/ as
java com.chase.impb.tokyo.matrix2.cfunds.CFTradeEntry
its worknig fine.
when i make a jar file for this class file and copy into d:/test and run the jar file from d:/test its not able to locate the image file.
Can somebody help me.
Do i need to pur the image also inside jar???
Regards
Radha
[ September 09, 2003: Message edited by: Radha MahaLakshmi ]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Yes. If you put it in the jar, inside an "images" directory, this will work fine.


[Jess in Action][AskingGoodQuestions]
Radha MahaLakshmi
Ranch Hand

Joined: Mar 28, 2003
Posts: 45
Hi
I put the gif file also inside the jar file.Still when i run it says it can not find the image.
Regards
Radha
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
ImageIcon icon = ClassLoader.getSystemResource("images/logo.gif");
Try this instead:
java.net.URL iconURL = ClassLoader.getSystemResource("images/logo.gif");
Image image = Toolkit.getDefaultToolkit().getImage(iconURL);
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to load an image from java program