Java SystemTray Icon

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

The problem is that I see the tray icon if I launch the application from eclipse, but I cannot see it if I export and run the jar executable. I have other images in my application that work perfectly in the same folder.

The tray works (left and right click on it), but does not show the image, as you can see in the image (jar file above, with an eclipse below):

Example of the Missing image

Why? Thank you and sorry for my english!

EDIT : I finally found a solution that needs to access the whit image:

Image img = Toolkit.getDefaultToolkit().getImage(MyClass.class.getResource("/images/asd.png")); 
+4
source share
1 answer

The problem is how you include the image file. You will need to include the image in the JAR when creating it, and you will have to access the image differently:

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

You can simply use the img variable to set the image to a JAR.

Update:

Take all the files and class images and go to the command line:

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

Replace Manifest.mft your manifest file name. Replace image.png image you want to display (you can add more images if you need)

+1
source

Source: https://habr.com/ru/post/1340261/


All Articles