I'm writing an application that utilizes Java's TrayIcon
class, but I can't seem to get it to display messages on Windows XP/Vista. Is this a known issue or is there something that I'm missing? (Messages appear as they should on Windows 7)
Code:
public class SysTray {
public static void main(String[] args) throws Exception {
TrayIcon icon = new TrayIcon(getImage());
icon.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null, "Good");
}
});
SystemTray.getSystemTray().add(icon);
icon.displayMessage("Attention", "Please click here",
TrayIcon.MessageType.WARNING);
}
private static Image getImage() throws HeadlessException {
Icon defaultIcon = MetalIconFactory.getTreeHardDriveIcon();
Image img = new BufferedImage(defaultIcon.getIconWidth(),
defaultIcon.getIconHeight(), BufferedImage.TYPE_4BYTE_ABGR);
defaultIcon.paintIcon(new Panel(), img.getGraphics(), 0, 0);
return img;
}
}
Edit: computers were both using the latest version of Java
Edit II: Results of tests on various computers:
- Windows XP, J7_25 (1.7.0_25-b16): Works
- Windows 7, J7_25 (1.7.0_25-b17): Works
- Windows XP, J7_25 (1.7.0_25-b17): Does not work