I'm getting familiar with NetBeans and doing my first tutorials with Java.
I'm not seeing my System Tray icon show up, and I suspect I placed the icon in the wrong location within the project files. Here's my code inside SysTray.java:
package systray;
import java.awt.*;
public class SysTray {
public static void main(String[] args) {
Runnable runner;
runner = new Runnable() {
public void run() {
if (SystemTray.isSupported()) {
SystemTray tray = SystemTray.getSystemTray();
Image image = Toolkit.getDefaultToolkit().getImage("MyIcon.png");
PopupMenu popup = new PopupMenu();
MenuItem item = new MenuItem("A MenuItem");
popup.add(item);
TrayIcon trayIcon = new TrayIcon(image, "The Tip Text", popup);
try {
tray.add(trayIcon);
} catch (AWTException e) {
System.err.println("Can't add to tray");
}
} else {
System.err.println("Tray unavailable");
}
}
};
EventQueue.invokeLater(runner);
}
}
I placed "MyIcon.png" inside the same directory as the SysTray.java (main). But I actually guessed that's where I should place it.
Here's the directory structure:
SysTray/
- Source Packages/ - systray/ - SysTray.java
- Source Packages/ - systray/ - MyIcon.png
- Libraries/
I see a blank space for the icon in the system tray, and when i hover my mouse I do see the "The Tip Text". But no icon.
I also received no error from NetBeans about a missing image. So, I'm stuck