Java systemtray Icon

A really simple tutorial on implementing a system tray icon

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

The tray is working (left and right click on it) but does not display the image, as you can see in the image (jar file at the top and eclipse at the bottom):

Why? Thank you, sorry for my English!

Editor: I finally found a solution that needs to access images:

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

Solution

The problem is how you include the image file You must include the image in the jar when you create the jar, and you must access the image in different ways:

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

You can use the IMG variable to set the image in the jar

to update:

Get all course files & images and go to the command line:

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

Set manifest Replace MFT with your manifest file name Set image PNG is replaced by the image you want to display (more images can be included if necessary)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>