Java SystemTray icon

2.8k views Asked by At

There is a really simple tutorial on implementing a system tray icon.

The problem is, I can see the icon in tray if I run my app from eclipse, but I can't see it if I export and run a runnable jar file. I have other images in my app that work fine form the same folder.

The tray is working (left and right click on it) but doesn't show the image, like you can see in the image (the jar file on top, with eclipse on bottom):

Example of the Missing image

Why? Thank you and sorry for my english!

EDIT: I finally found the solution the image need to be accessed whit:

Image img = Toolkit.getDefaultToolkit().getImage(MyClass.class.getResource("/images/asd.png"));
1

There are 1 answers

8
AudioBubble On

The problem is the way you include the image file. You will have to include the image in the JAR when you create it, and you will have to access the image in a different manner:

try {
    InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream("wing16.png");
    BufferedImage img = ImageIO.read(is);
}
catch (IOException e) {}

You can just used the img variable to set the image in the JAR.

Update:

Take all of your class files & images and go to command line:

jar -cvfm Test.jar Manifest.mft *.class image.png

Replace Manifest.mft with your manifest file name. Replace image.png with the image you want to show up (you can include more images if you need to)