How to build a jar file with an icon for the tray?

47 Views Asked by At

I'm building an application to run in the tray. Of course, it has to display an icon in the tray, but I don't know why it doesn't work for me.

When I compile myself in IntelliJ, it all works nicely, but when I build the jar file it doesn't display the correct icon.

This is my code responsible for adding the icon

 Image img =Toolkit.getDefaultToolkit().getImage("src/main/resources/bsx.png");
 TrayIcon trayIcon = new TrayIcon(img, "Loop Driver", popupMenu);

 trayIcon.setImageAutoSize(true);
 trayIcon.setPopupMenu(popupMenu);

 try{
   systemTray.add(trayIcon);
 } catch (AWTException e) {
   throw new RuntimeException(e.getMessage());
 }

when I compile in IntelliJ I have the icon I want in the tray

enter image description here

but when I build jar file I have

enter image description here

In Project Structure I have that

enter image description here

what am I doing wrong?

I try many solution and configuration but nothing work.

0

There are 0 best solutions below