1

I have an TrayIcon which occasionally displays popup/balloon messages via displayMessage(). The TrayIcon itself has an ActionListener which works fine. As per the docs, on at least some platforms (eg Win 8), a click on the message bubble itself fires the icon's listener event.
So far so good, but I would like to implement separate behaviour for

  1. The user clicking the icon itself in the system tray
  2. The user clicking the message bubble (in this case, do nothing)

Is there an elegant way of doing this?
I thought there might be a property of the ActionEvent passed to ActionListener.actionPerformed() which could distinguish between the two sources of a click, but can't find one.

Any ideas? The app will only run on Windows, if that helps.

michael256
  • 71
  • 6
  • you can attach an ActionListener directly to the TrayIcon, if that fails, you can try using the MouseListener support which should take care of case 1 – MadProgrammer May 06 '15 at 10:06

1 Answers1

0

I had a method to display the message in the balloon on my system tray icon whenever I push a message using my rest service. You can add an action listener to the displayed message which you can use to do anything in the actionperfomed method.

public void displayMessage(String psTitle, String psMessage, final MessageType poType){
    moTrayIcon.displayMessage(psTitle, psMessage, poType);
    moTrayIcon.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                Desktop dst = Desktop.getDesktop();
                String location = "D:\\dev";
                dst.open(new File(location));
                //location = "D:\\"; // again setting root location                    
            } catch (Exception ex) {
                LOGGER.error("------- error with folder opening double click "
                        + ex.getMessage());
            }

        }
    });

}
Floern
  • 33,559
  • 24
  • 104
  • 119