任务栏通知气球事件? [英] Task tray notification balloon events?

查看:85
本文介绍了任务栏通知气球事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任务栏图标通知气球上是否可以调用任何Java event, 那是

Is there any java event that could be called on the task tray icon notification balloon, that is

trayIcon.displayMessage(title, message, TrayIcon.MessageType.INFO)

就像保管箱一样,当我单击气球时,它会将我带到下载了最新文件的文件夹中.可以使用Java吗?

like dropbox uses, when I click on the balloon it take me to the folder where it had downloaded the recent file. Is it possible using java?

推荐答案

通过进行一些R& D,当我们单击通知气球时,我得到了托盘图标double click event被调用.这就是我想要的.

By doing some R&D I got that tray icon double click event get called when we click on the notification balloon. This is what I was looking for.

检查此代码:

public class Main {
  static Image image = Toolkit.getDefaultToolkit().getImage("images/tray.gif");

  static TrayIcon trayIcon = new TrayIcon(image, "Tester2");

  public static void main(String[] a) throws Exception {
    if (SystemTray.isSupported()) {
      SystemTray tray = SystemTray.getSystemTray();

      trayIcon.setImageAutoSize(true);
      trayIcon.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          System.out.println("In here");
          trayIcon.displayMessage("Tester!", "Some action performed", TrayIcon.MessageType.INFO);
        }
      });

      try {
        tray.add(trayIcon);
      } catch (AWTException e) {
        System.err.println("TrayIcon could not be added.");
      }
    }
  }
}

然后我以这种方式为我修改了它.

and I modified it for me in this way.

private static String location = Roor_Location_Here// contain the root location

然后双击event

/*
 * Double click action performed *
 */
trayIcon.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
        try {
            Desktop dst = Desktop.getDesktop();
            dst.open(new File(location));
            /*
             * reset the location to root location again.
             */
            location = Root_Location_Here // again setting root location                    
        } catch (Exception ex) {
            logger.error("------- error with folder opening double click "
                    + ex.getMessage());
        }
    }
});

这是我用来调用通知气球以显示消息的功能:

And this is the function I use to call for notification balloon to show the message:

public static void showNotification(String title, String msg,
            String location) {
    if (SystemTray.isSupported()) {
        trayIcon.displayMessage(title, msg, TrayIcon.MessageType.INFO);
        SystemTrayGUI.location = location;// this sets the location that should be opened when balloon is clicked.

    }
}

这篇关于任务栏通知气球事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆