• 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

IDE: eclipse; Problem: embedded Images

 
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi huys,

How can embedd the images to the JAR file? I don't want the end-user to change the icons/images that I use.
 
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there a specific problem you're having?

To include images in a jar file using eclipse you would simply select the folder they are in to be included when you do an export to jar file.
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my refrence to the images is from a folder (images) so it goes like this:

this.exitButton = new JButton("Exit", new ImageIcon("images/Exit.gif"));


but the folder images must exist on the client side (and he has access to it)
how can I refer to the jar's images folder?
 
Steven Bell
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
use this.getClass().getResource() or getResourceAsStream methods to access images in a jar.
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Steven,

I tried this:
protected JButton timeStamp = new JButton ("Timestamp (Alt + t)", new ImageIcon(this.getClass().getResource("images/ts.png")));

and this
protected JButton timeStamp = new JButton ("Timestamp (Alt + t)", new ImageIcon(this.getClass().getResource("images.rar/ts.png")));

nothing. Am I on the right track?
 
Steven Bell
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The first one should work, you just have to make sure there is a top level folder 'images' in the jar file with the ts.png file in it. (This assumes you are using Java 1.3 or later as that's when png support was introduced)

If the images are in a rar file (a guess from your second piece of code) you will need to extract them and place them in an images folder before building the jar.
 
I miss the old days when I would think up a sinister scheme for world domination and you would show a little emotional support. So just look at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic