Vinay
Vinay

Reputation: 347

images are not displaying in executable jar

i have created executable jar file of my project built in eclipse. but when i execute that file then it does not display icon on system tray that i have added in project. i am using 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);

Upvotes: 5

Views: 2850

Answers (1)

Jakub Zaverka
Jakub Zaverka

Reputation: 8874

To load resources from within .jar files please use getClass().getResource(). That will return a URL with correct path.

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

Upvotes: 5

Related Questions