• Post Reply Bookmark Topic Watch Topic
  • New Topic

Exporting to executable jar, not showing icons  RSS feed

 
Ranch Hand
Posts: 34
1
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am using Eclipse as my IDE and everything works just as expected unfortunately when I export the project to a executable JAR is fails to display the icons, can some one advise what I am doing wrong.

This is a couple of the places I expect to see ICONS.

static JMenuItem mnuItemQuit = new JMenuItem("Quit", new ImageIcon("res/images/quit.png"));
static JMenuItem mnuItemAbout = new JMenuItem("About", new ImageIcon("res/images/about.png"));


res has been added as a library resources and everything looks good until I export to JAR.

Many Thanks.
 
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the structure of the JAR file you have created? Can you show us what folders/files are in there please?
 
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The ImageIcon constructor you are using takes a String parameter for the filename. Resources insinde a jar aren't files. You need to use the ImageIcon(URL) constructor.

Have you discovered the Oracle tutorials? There's a section that explains all this: Loading Images Using getResource
 
Ricardo Wagemaker
Ranch Hand
Posts: 34
1
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
James Boswell wrote:What is the structure of the JAR file you have created? Can you show us what folders/files are in there please?



Project/src/package/files.java

Added as a library--

Project/res/audio/....
Project/res/images/....

As I say it works perfect in Eclipse until I export it to runnable JAR

P.S.

I tried:

/res/images/...
re/images/...
/images/...
images/...
just_file_name.png
 
Ricardo Wagemaker
Ranch Hand
Posts: 34
1
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Problem solved.

ImageIcon iconQuit =new ImageIcon(getClass().getResource("/images/quit.png") );

public JMenuItem mnuItemQuit = new JMenuItem("Quit", iconQuit );


Changed the JMenuItem to public rather than static and then used the getResources to load the images.

Exported to JAR and it all works.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!