File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

IDE: eclipse; Problem: embedded Images

 
Peter Primrose
Ranch Hand
Posts: 755
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Steven Bell
Ranch Hand
Posts: 1071
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use this.getClass().getResource() or getResourceAsStream methods to access images in a jar.
 
Peter Primrose
Ranch Hand
Posts: 755
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic