aspose file tools*
The moose likes IDEs, Version Control and other tools and the fly likes IDE: eclipse; Problem: embedded Images Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "IDE: eclipse; Problem: embedded Images" Watch "IDE: eclipse; Problem: embedded Images" New topic
Author

IDE: eclipse; Problem: embedded Images

Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
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

Joined: Dec 29, 2004
Posts: 1071
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

Joined: Sep 10, 2004
Posts: 755
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

Joined: Dec 29, 2004
Posts: 1071
use this.getClass().getResource() or getResourceAsStream methods to access images in a jar.
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
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

Joined: Dec 29, 2004
Posts: 1071
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 agree. Here's the link: http://aspose.com/file-tools
 
subject: IDE: eclipse; Problem: embedded Images