• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Loading an Image

 
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
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Radha
First: The getSystemResource of the class ClassLoader don�t returns a ImageIcon, it returns a URL !!
When you put all classes into a jar file, you must to use all pictures into jar too !!!

Originally posted by Radha MahaLakshmi:
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

 
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
Thanks for the reply.
Yeah i am using thst URL to construct object of ImageIcon like below.
new ImageIcon(imgURL, description).
Could you please let me know how to put imgae in jar file
my imgae is in a directory c:/images/logo_jpmf.gif.
while creating jar file if i say
jar -cf cfunds.jar /com/chase/impb/tokyo/matrix2/cfunds/*.class ,/images/logo_jpmf.gif
its giving error.
Can you please tell me how to create a jar file by includingh the image.
After that do i need to copy the image where ever i put this jar or would it take from jar file only???
Regards
Radha
[ September 09, 2003: Message edited by: Radha MahaLakshmi ]
[ September 09, 2003: Message edited by: Radha MahaLakshmi ]
 
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 am able to include the image in jar file but still its not able to locate the file.
here i am pasting the code
ImageIcon createImageIcon(String path, String description)
{
System.out.println("-------path:"+path);
try
{
URL imgURL = ClassLoader.getSystemResource(path);
System.out.println("-------imgURL:"+imgURL);
if (imgURL != null) {
return new ImageIcon(imgURL, description);
} else {
System.err.println("Couldn't find file: " + path);
return null;
}
}catch(Exception e)
{
e.printStackTrace();
}
return null;
}
this function i am using as below
ImageIcon icon = createImageIcon("images/logo_jpmf.gif", "logo");
JLabel title = new JLabel(" Commingled Funds Trade Entry ", icon, JLabel.LEFT);

Regards
Radha
 
Silvio Fragata da Silva
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The path into your jar is equals to the path into code
Ex.: "images/logo_jpmf.gif"
into jar
archive.jar
images
|
---logo_jpmf.gif
 
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 could able to put my image files inside jar and whn i run its not able to find the files.
Still its not able to find the images.
Is thare any thing wrong in my code???
Here is the functions i am using
ImageIcon createImageIcon(String path, String description) {
System.out.println("-------path:"+path);

URL imgURL = ClassLoader.getSystemResource(path);

System.out.println("-------imgURL:"+imgURL);
if (imgURL != null) {
return new ImageIcon(imgURL, description);
} else {
System.err.println("Couldn't find file: " + path);
return null;
}
}
above function i am usng as below
ImageIcon icon = createImageIcon("images/logo_jpmf.gif", "logo");
JLabel title = new JLabel(" Commingled Funds Trade Entry ", icon, JLabel.LEFT);
Regards
Radha
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic