我已经成功地创建了一个通知弹出窗口10行动中心使用这个答案。问题是,通知在那里停留了5秒,然后一旦它消失,就会从操作中心完全删除。如何使操作中心保留通知,直到用户拒绝通知为止?以下是代码:
import java.awt.*;
import java.awt.TrayIcon.MessageType;
import javax.swing.JOptionPane;
public class Win10Notif {
public static void main(String[] args) throws AWTException, java.net.MalformedURLException {
if (SystemTray.isSupported()) {
Win10Notif td = new Win10Notif();
td.displayTray();
} else {
System.err.println("System tray not supported!");
}
}
public void displayTray() throws AWTException, java.net.MalformedURLException {
//Obtain only one instance of the SystemTray object
SystemTray tray = SystemTray.getSystemTray();
//If the icon is a file
Image image = Toolkit.getDefaultToolkit().createImage("icon.png");
//Alternative (if the icon is on the classpath):
//Image image = Toolkit.getToolkit().createImage(getClass().getResource("icon.png"));
TrayIcon trayIcon = new TrayIcon(image, "Tray Demo");
//Let the system resizes the image if needed
trayIcon.setImageAutoSize(true);
//Set tooltip text for the tray icon
trayIcon.setToolTip("System tray icon demo");
tray.add(trayIcon);
trayIcon.displayMessage("Hello, World", "notification demo", MessageType.INFO);
}
}发布于 2017-06-16 16:58:52
我认为这是由Windows本身管理的,或者是JVM的本机实现。至少,公共API没有提供在屏幕上设置通知的特定时间的选项。
除非您需要坚持操作中心,否则可以考虑使用外部库进行桌面通知,如下所示:
JOptionpane.showMessageDialog()相同的方式使用,也可以在手动提交通知对象之前构建和自定义通知对象。属性,如颜色主题,图标,在屏幕上的时间和动作可以定制,还提供股票主题和图标。你可以免费抓取并试用其中任何一个。
https://stackoverflow.com/questions/41906067
复制相似问题