创建 Java 个桌面通知

Create Java Desktop Notification

要求是创建一个可以注册点击事件的桌面通知。我无法使用网络套接字或任何浏览器通知。
我无法使用 Tray-Icons 和 SystemTray,因为它们无法在 DISPLAY MESSAGE 上注册 Click-Events。他们可以在托盘图标上有点击事件,但不能在显示消息上。最接近的例子 - "When we register a click on a Skype message, it opens Skype for us"

截图



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

我使用了来自 github DorkBox.
的以下存储库 只需按照 github link 中的说明添加 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.

在您的主块中添加以下代码,一切顺利。