When using TrayIcon.displayMessage to show a popup notification, the Java 6 documentation states that 'Clicking on the message may trigger an ActionEvent.'
'May'? Thanks, documentation.
On my Windows 2000 test VM, clicking on the message does not appear to trigger an ActionEvent (unfortunately I don't own any newer Windows licenses to test), while the same code does trigger one in Ubuntu and OS X.
Note: Clicking on the icon itself does trigger an event on the mouse listener.
So anyway, my specific questions are:
Am I correct that clicking the notification does not trigger an ActionEvent in Windows 2000, or is there something I'm doing wrong?
Does it work to trigger an ActionEvent in Windows XP or Windows 7?
Minimal sample code is below. When I run this using java Test
in Windows 2000, clicking on the notification does not generate any command-line output.
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import javax.swing.SwingUtilities;
public class Test
{
public static void main(String[] args)
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
TrayIcon icon = new TrayIcon(
new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB));
icon.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent arg0)
{
System.err.println("ActionEvent: " + arg0);
}
});
try
{
SystemTray.getSystemTray().add(icon);
}
catch(AWTException e)
{
e.printStackTrace();
}
icon.displayMessage("New message", "Can you click on this?",
TrayIcon.MessageType.INFO);
}
});
}
}
The problem you're dealing with is a cross platform implantation issue, that's why it 'may' trigger an event