是否有任何可以在任务托盘图标通知气球上调用的 java event
,
那是
trayIcon.displayMessage(title, message, TrayIcon.MessageType.INFO)
就像 Dropbox 使用的那样,当我单击气球时,它会将我带到下载最近文件的文件夹。可以使用java吗?
最佳答案
通过进行一些研发,当我们点击通知气球时,我得到了托盘图标 double click event
被调用。这就是我一直在寻找的。
检查此代码:
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.");
}
}
}
}
我以这种方式为我修改了它。
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());
}
}
});
这是我用来调用通知气球以显示消息的函数:
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.
}
}
关于java - 任务托盘通知气球事件?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13989265/