• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

How to load an image from java program

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
 
What could go wrong in a swell place like "The Evil Eye"? Or with this tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic