• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problems dispaying icon

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a package called divelog, with a subdirectory of images, with a file diveflag.gif
I am trying to load a image into a label by:
jl = new JLabel("Java(TM) Technology Dive Log", new ImageIcon("images/diveflag.gif"), JLabel.CENTER);

When I run the application no image appears. Any ideas?
Thanks,
Dean
 
Dean Reedy
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I added the full path from where the JAVA machine was running and it worked. I thought you only had to path it from where the class files exists. Does anyoine know the rules?
thanks,
Dean
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think Java uses the CLASSPATH to search for images also... is the directory directly above /images on the classpath?
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The '/images' subdirectory must be a subdirectory of the directory where the code is located that calls for the image. For instance, if the code for divelog.java is located at 'C:\MyApps\divelog', then the '/images' sub must be located at 'C:\MyApps\divelog\images'. The CLASSPATH knows where to find it because it starts at the current directory, and your code gives it a relative path to the *.gif file, 'new ImageIcon("images/diveflag.gif"), JLabel.CENTER);', (the part in the double quotes).
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic