Images are not displayed in the executable bank

I created the jar executable of my project embedded in eclipse. but when I execute this file, it does not display the icon on the system tray that I added in the project. I am using the following simple code.

Image image = Toolkit.getDefaultToolkit().getImage("src/resources/ChatIcon1.jpeg"); PopupMenu Popup = new PopupMenu(); MenuItem exit = new MenuItem("Exit"); Popup.add(exit); final TrayIcon trayIcon = new TrayIcon(image,"OfficeCommunicator",Popup); trayIcon.setImageAutoSize(true); 
+4
source share
1 answer

To load resources from .jar files, use getClass (). getResource (). This will return the URL with the correct path.

 Image img = ImageIO.read(getClass().getResource("path to image")); 
+5
source

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


All Articles