File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Swing / AWT / SWT
Image inside jar file
Joined: Jan 07, 2007
Nov 30, 2007 01:30:00
I have to display some icons in the GUI which i create. I have included the following gif files in the code:
Image logo = Toolkit.getDefaultToolkit().getImage("icon/iconAbc.gif"); Icon openicon = new ImageIcon("icon/open.gif"); Icon saveicon = new ImageIcon("icon/Save.gif"); Icon saveasicon = new ImageIcon("icon/Saveas.gif"); Icon exiticon = new ImageIcon("icon/exit.gif"); Icon cuticon = new ImageIcon("icon/cut.gif"); Icon copyicon = new ImageIcon("icon/copy.gif"); Icon pasteicon = new ImageIcon("icon/paste.gif"); Icon findicon = new ImageIcon("icon/find.gif"); Icon Abouticon = new ImageIcon("icon/small.gif");
I created a seperate icon package and copied all those images inside this package.
When i create an executable jar and run it, these icon images are not getting displayed in the interface.
Kindly provide your help in resolving this problem.
Joined: Mar 22, 2005
Nov 30, 2007 02:35:00
) constructor expects a file name as parameter, so that won't work. Something like the following should do the trick:
java.net.URL imgURL = getClass().getResource("icon/open.gif"); ImageIcon icon = new ImageIcon(imgURL);
You may have to fiddle around with the path name, and whether or not there needs to be a slash in front of it.
I agree. Here's the link:
subject: Image inside jar file
Accessing jar file contents
Where to store image files?
Problems loading images from application JAR
adding .jpg file to a jar file
Is it okay to use images found on the web?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015