我有一个JEditorPane,在JOptionPane中显示一个我想在关闭我的应用程序之前打开的URL。它在Windows和Linux上运行良好,但在Mac上无法使用。JEditorPane中的超链接无法在MAC上打开
下面是代码:
//LINK
String link = "http://www.google.com/";
String link_name = "Google";
//Editor_Pane
JEditorPane editor_pane = new JEditorPane();
editor_pane.setEditorKit(JEditorPane.createEditorKitForContentType("text/html"));
editor_pane.setText(/*some text*/ + "<a href=\"" + link + "\">" + link_name + "</a>");
editor_pane.setEditable(false);
//ADD A LISTENER
editor_pane.addHyperlinkListener(new HyperlinkListener(){
public void hyperlinkUpdate(HyperlinkEvent e){
if(e.getEventType() == (HyperlinkEvent.EventType.ACTIVATED)){
//OPEN THE LINK
try{ Desktop.getDesktop().browse(e.getURL().toURI());
}catch (IOException | URISyntaxException e1) {e1.printStackTrace();}
//EXIT
System.exit(0);
}
}
});
//SHOW THE PANE
JOptionPane.showOptionDialog(null, editor_pane, "text", JOptionPane.DEFAULT_OPTION,
JOptionPane.PLAIN_MESSAGE, null, new Object[] {}, null);
的链接似乎可点击的,但是当我点击,即使我尝试删除Desktop.browse
方法,让只有exit
方法没有任何反应。
我在做什么错?谢谢 !
为了更好地帮助越早,张贴[MCVE]或[简要,独立的,正确的示例](http://www.sscce.org/)。 –