• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

How to load an image from java program  RSS feed

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
author and iconoclast
Sheriff
Posts: 24220
40
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. If you put it in the jar, inside an "images" directory, this will work fine.
 
Radha MahaLakshmi
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!