创建 Java 桌面通知

Kar*_*aur 3 java notifications desktop-application push-notification

要求是创建一个可以注册点击事件的桌面通知。我不能使用网络套接字或任何浏览器通知。
我无法使用 Tray-Icons 和 SystemTray 因为它们无法在 DISPLAY MESSAGE 上注册Click-Events。他们可以在托盘图标上有点击事件,但在显示消息上没有。最接近的例子 - “当我们点击 Skype 消息时,它会为我们打开 Skype”

截屏


Skype 通知弹出窗口


单击上面的通知 Skype 聊天打开。Tray-Icons 不支持相同的功能。要么解决它,要么采用新方法。
希望我清楚谢谢。

Kar*_*aur 5

我使用了来自 github DorkBox的以下存储库。
只需按照 github 链接中的说明添加 maven 依赖项。但是,我无法检查如何更改通知的 UI。

Notify.create()
      .title(text)
      .text(title)
      .position(Pos.TOP_RIGHT)
      .onAction( new ActionHandler<Notify>() {
            @Override
            public void handle(Notify value) {
                if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
                    try {
                        Desktop.getDesktop().browse(new URI(targetUrl));
                    } catch (IOException e) {
                        e.printStackTrace();
                    } catch (URISyntaxException e) {
                        e.printStackTrace();
                    }
                }
            }
      })
      .hideAfter(5000)
      .shake(250, 5)
      .darkStyle()      // There are two default themes darkStyle() and default.
      .showConfirm();   // You can use warnings and error as well.
Run Code Online (Sandbox Code Playgroud)

在您的主块中添加以下代码,您就可以开始了。