java – 任务托盘通知气球事件?
作者:互联网
是否可以在任务托盘图标通知气球上调用任何java事件,
那是
trayIcon.displayMessage(title, message, TrayIcon.MessageType.INFO)
像Dropbox一样,当我点击气球时,它会将我带到它下载最近文件的文件夹.是否可以使用java?
解决方法:
通过做一些R& D,当我们点击通知气球时,我得到了托盘图标双击事件.这就是我想要的.
检查此代码:
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
然后在双击事件中
/*
* 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,listener,swing,notifications,system-tray 来源: https://codeday.me/bug/20190713/1450482.html