Java windows通知_java – 创建Windows 10持久性通知

我已经使用

this answer在Windows 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);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值