• 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

Loading icon files from JAR (or directory)

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. How can I load icons from a JAR file?
2. Will the same piece of code work if the JAR is unzipped?

I've found a handful of posts that pose question #1 exactly, and in each case there was a solution that led to a happy ending. Not so in my case. Here are the solutions that I found:

a. use ClassLoader.getSystemResource(), then getToolKit().getImage()
b. use this.getClass().getResource(), then toolkit.createImage()
c. use this.getClass().getClassLoader(), then new ImageIcon()

The Developer's Guide (Application Development Considerations) suggested "c". None of them work for me, the icon just refuses to be found.

I'd appreciate any help at all, otherwise it's back to head banging for me.

I've also seen references to "user.dir" to qualify the filename, but I don't understand why that would be required.
 
Stephen Tracey
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, I got it.

Thanks for letting me sweat it out. Sometimes one needs that, rather than a quick answer.

I use Eclipse, and I wasn't treating my icons as source files -- so they weren't being copied into the bin directory with my class files. Simple as that. 2 of the 3 approaches above worked, I'd guess that the other one works also.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic