• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Loading icon files from JAR (or directory)

 
Stephen Tracey
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic