【发布时间】:2015-07-30 23:30:46
【问题描述】:
我正在尝试使用超链接实现 JEditorPane。我正在使用 HyperLinkListener,但它似乎永远不会触发。
代码:
JEditorPane editorPane = new JEditorPane("text/html", programInfo);
editorPane.addHyperlinkListener(e -> {
System.out.println("CLICK");
if (e.getEventType().equals(HyperlinkEvent.EventType.ENTERED))
try {
if (Desktop.isDesktopSupported()) {
Desktop.getDesktop().browse(e.getURL().toURI());
}
} catch (IOException e1) {
e1.printStackTrace();
} catch (URISyntaxException e1) {
e1.printStackTrace();
}
});
JOptionPane.showMessageDialog(contentPane, editorPane);
示例 HTML:
<body>
<p><b>Author:</b> James - <a href="http://www.sample.co.uk">sample</a></p>
</body>
这导致了:
但是当我点击链接时没有任何反应。
其他信息:
我正在 Ubuntu 14.04 上对此进行测试。 我已将外观设置为系统。
【问题讨论】: