• 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

URL - Placement of Image Files  RSS feed

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've got the following statement in a class that creates an imageIcon:

"ImageIcon hiImage = new ImageIcon("images/hi.jpg");"

In order for this image to be loaded when the program is executed, I know that the "hi.jpg" file needs to be in a folder named "images". But where do I put that folder? Do I need to somehow zip it up in the JAR file for my finished program? I'm a little confused about where the JVM is going to look for the "images" folder....

Thanks for the help,

Landon
 
Ranch Hand
Posts: 524
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Landon Blake,
What the JVM does is it goes to the default directory in search of the source files and images etc. The dafult directory can be the JAVA_HOME\bin or the folder that you have mentioned when setting the CLASS path. In your case the image folder should reside inside this default folder.
Hope I was able to clear your doubt. Just reply if you need any more clarifications....
 
Landon Blake
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ransika,

First, I want to thank you for your response. It did answer my original question. However, it did raise another question.

If I package up my program into a jar file, "test.jar", and I want a user on another computer to execute the jar file and run my program, where do I place the images so that they display properly in the Swing GUI? Must my program install a directory on the users file system that is in the classpath? Isn't there a way to "wrap up" the images in the jar file so the JVM looks for the files in the jar itsel or in the same directory that the jar is in? (Or perhaps I can package the jar and the directory for the images in a zip file. When the user unzips the file, the directory with the images and the jar file is extracted to the same location on the file system. Would this work?)

Thanks,

Landon
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!