I've been trying all day to get my tray icon added, but it doesnt work. I have the icon file stored within the netbeans src/myproject/
I have tried a gazillion different paths, even direct ones to my files, but none seem to work. I'm pretty sure something in my code doesnt work, I simply can't see it.
public void createSystemTrayIcon() {
if (SystemTray.isSupported()) {
SystemTray tray = SystemTray.getSystemTray();
Image img = Toolkit.getDefaultToolkit().getImage("smallicon.ico");
PopupMenu popup = new PopupMenu();
final MenuItem menuExit = new MenuItem("Quit");
MouseListener mouseListener =
new MouseListener() {
public void mouseClicked(MouseEvent e) {
show();
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
}
};
ActionListener exitListener =
new ActionListener() {
public void actionPerformed(ActionEvent e) {
Runtime r = Runtime.getRuntime();
System.out.println("Exiting...");
r.exit(0);
}
};
menuExit.addActionListener(exitListener);
popup.add(menuExit);
final TrayIcon trayIcon = new TrayIcon(img, "ESOLeaderboards", popup);
ActionListener actionListener =
new ActionListener() {
public void actionPerformed(ActionEvent e) {
trayIcon.displayMessage("ESOLeaderboards ","version: EU 1.0",
TrayIcon.MessageType.INFO);
}
};
trayIcon.setImageAutoSize(true);
trayIcon.addActionListener(actionListener);
trayIcon.addMouseListener(mouseListener);
try {
tray.add(trayIcon);
} catch (AWTException e) {
System.err.println("TrayIcon could not be added.");
}
} else {
// System Tray is not supported
}
}
Toolkit.getDefaultToolkit().getImage("smallicon.ico");
supports only JPG, PNG and GIF images.It doesn't support ico images. Use another image.