user1639485
user1639485

Reputation: 808

Executable jar doesn't show up the icons/images used in the application

While writing my application (used Eclipse as my IDE), I didn't realize the problem that my images would not be eventually bundled in the jar. Now after completing the project and creating the executable jar, I bumped into this problem. I have around 50 java classes, and I have used images/icons extensively in most of these classes (e.g. in menus, as JLabel icon, in buttons, as tab icons, etc). I have used the ImageIcon API in most of the cases. One example:

JLabel myHeaderImage = new JLabel(new ImageIcon("images/myHeader.jpg"));

What's the best way to pull in the images in the jar. Do I need to change the way I have used the images in my project?

Upvotes: 0

Views: 3311

Answers (2)

Damian
Damian

Reputation: 1

Just put a full path to ur images, such as in my case:

ImageIcon icon = new ImageIcon("X:/ProjektyNetBeans/GUITest/src/data/world.png");

Then Clean and Build. File .jar will work fine. Good luck.

Upvotes: 0

Rempelos
Rempelos

Reputation: 1220

Use getResource():

JLabel myHeaderImage = new JLabel(new ImageIcon(getClass().getResource("/images/myHeader.jpg")));

Upvotes: 2

Related Questions