NoN*_*aMe 3 java notifications swing system-tray listener
是否event可以在任务托盘图标通知气球上调用任何java ,即
trayIcon.displayMessage(title, message, TrayIcon.MessageType.INFO)
Run Code Online (Sandbox Code Playgroud)
像Dropbox一样,当我点击气球时,它会将我带到它下载最近文件的文件夹.是否可以使用java?
NoN*_*aMe 15
通过做一些研发,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.");
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我以这种方式为我修改了它.
private static String location = Roor_Location_Here// contain the root location
Run Code Online (Sandbox Code Playgroud)
然后双击 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());
}
}
});
Run Code Online (Sandbox Code Playgroud)
这是我用来调用通知气球来显示消息的函数:
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.
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21064 次 |
| 最近记录: |