Java 如何使气球通知中的URL可单击?

Java 如何使气球通知中的URL可单击?,java,intellij-idea,intellij-plugin,Java,Intellij Idea,Intellij Plugin,我正在创建一个简单的IntelliJ插件,它允许直接从IDE创建新的Pastebin粘贴 当粘贴成功发布到Pastebin时,我想显示一个气球通知 当前,通知显示如下: final Response<String> postResult = Constants.PASTEBIN.post(paste); NotificationGroup balloonNotifications = new NotificationGroup("Notification group"

我正在创建一个简单的IntelliJ插件,它允许直接从IDE创建新的Pastebin粘贴

当粘贴成功发布到Pastebin时,我想显示一个气球通知

当前,通知显示如下:

final Response<String> postResult = Constants.PASTEBIN.post(paste);
        NotificationGroup balloonNotifications = new NotificationGroup("Notification group", NotificationDisplayType.BALLOON, true);
        if (postResult.hasError()) {
            //Display error notification
        } else {
            //Display success notification
            Notification success = balloonNotifications.createNotification("Successful Paste", "<a href=\"" + postResult.get() + "\">Paste</a> successfully posted!", NotificationType.INFORMATION, null);
            Notifications.Bus.notify(success, project);
        }
final Response postResult=Constants.PASTEBIN.post(粘贴);
NotificationGroup BalloodNotifications=新建NotificationGroup(“通知组”,NotificationDisplayType.BALLOON,true);
if(postResult.hasError()){
//显示错误通知
}否则{
//显示成功通知
通知成功=ballonotifications.createNotification(“成功粘贴”,“成功发布!”,NotificationType.INFORMATION,null);
通知.总线.通知(成功,项目);
}
现在,此气泡通知包含新创建的粘贴的URL,但不幸的是,单击它不会在浏览器中打开链接。如何才能做到这一点

带有URL的气球通知应可单击:

经过一番搜索,我自己找到了答案。其实并不难

如果我按如下方式实例化通知,则可以根据需要单击该链接

Notification success = balloonNotifications.createNotification("<html>Successful Paste", "<a href=\"" + postResult.get() + "\" target=\"blank\">Paste</a> successfully posted!</html>", NotificationType.INFORMATION, (notification, hyperlinkEvent) -> {
            if (hyperlinkEvent.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                BrowserUtil.browse(hyperlinkEvent.getURL());
            }
        });
Notification success=ballonotifications.createNotification(“成功粘贴”,“成功发布!”,NotificationType.INFORMATION,(通知,hyperlinkEvent)->{
如果(hyperlinkEvent.getEventType()==hyperlinkEvent.EventType.ACTIVATED){
browse(hyperlinkEvent.getURL());
}
});

注意:现在还可以单击事件日志中的链接,这一点也非常有用。

有NotificationListener可以在通知中打开URL:com.intellij.notification.UrlOpeningListener

所以你可以写:

Notification success = balloonNotifications.createNotification(
            "<html>Successful Paste", "<a href=\"" + postResult.get() + "\" target=\"blank\">Paste</a> successfully posted!</html>",
            NotificationType.INFORMATION, new NotificationListener.UrlOpeningListener(true));
Notification success=balloodnotifications.createNotification(
“成功粘贴”,“成功发布!”,
NotificationType.INFORMATION,新建NotificationListener.UrlOpeningListener(true));

您是否尝试过用
标记环绕您的邮件?@BastienJansen是的,我尝试过,但这并没有改变任何事情。@BastienJansen事实上它做了一些事情,当您将鼠标悬停在链接上时,您会得到一个不同的光标。但是点击它仍然没有任何作用。谢谢你的回答。它比我最初找到的解决方案要干净得多。