我希望使用Java显示托盘通知,例如当磁盘空间不足时,Windows中出现的通知,没有防病毒软件等。
正是这样。
答案 0 :(得分:5)
答案 1 :(得分:4)
我想也许你应该看看TrayIcon.displayMessage
我知道实现你想要的唯一另一种方式是通过JNI
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
Image img = null;
try {
img = ImageIO.read(new File("..."));
} catch (IOException e) {
e.printStackTrace();
}
TrayIcon ti = new TrayIcon(img, "Tooltip");
try {
// You need to add it to the system tray first
SystemTray.getSystemTray().add(ti);
} catch (AWTException ex) {
ex.printStackTrace();
}
ti.displayMessage("Low Disk Space", "Diskspace is very low",
MessageType.WARNING);
}
});