This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Exporting to executable jar, not showing icons  RSS feed

 
Ranch Hand
Posts: 42
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: 42
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: 42
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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!