• 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

Where to store image files?

 
Ranch Hand
Posts: 672
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When my java is in the default package (source code in javasrc folder) I put images in
C:/javasrc/images folder. And the following code will work:
Icon icon = new ImageIcon("Images/cat.gif");
When I use a package name for my class (source code in javasrc/mypackage folder) then I put images in C:/javasrc/mypackage/images. Then the program can not find the image file.
Why?
 
Ranch Hand
Posts: 529
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's because when you actually run the program, you are running from javasrc directory, right? The path to your images has nothing to do with where your class files reside. It starts with whatever directory you are running from. So you will have to include the full path to your images in the Icon declaration, or leave the images in the /images directory. Hope this helps!

Barry
 
Bruce Jin
Ranch Hand
Posts: 672
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Barry.
It appears that when I package my class (source code in javasrc/mypackage folder) I have to store images in C:/javasrc/images folder. And the following code will work:
Icon icon = new ImageIcon("Images/cat.gif");
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic