Java program that appeared several times in the system tray

I created an application that hides in the system tray through the SystemTray class. It works fine, but when I exit the program and start it again, it does not remove the icon from the tray before pointing it to the pointer. Performing this several times, you will see several icons:

enter image description here

Is this a problem with my program or is it a Windows error?

I made this guide to create a system tray icon.

+4
source share
2 answers

When the application that created the tray icon terminates, Windows does not automatically delete the tray icon. This only happens when the user hovers over it and notices that the ownership process no longer exists.

To make sure the icon is removed immediately, you must call systemTray.remove(yourIcon) when your program is complete.

+6
source

The system tray contains one or more tray icons that are added to the tray using the add(java.awt.TrayIcon) method add(java.awt.TrayIcon) . They can be removed if they are no longer needed using the remove(java.awt.TrayIcon) method remove(java.awt.TrayIcon) .

+1
source

All Articles