JEditorPane 超链接摆动 html [英] JEditorPane Hyperlink swing html
本文介绍了JEditorPane 超链接摆动 html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我很难让超链接在 JEditorPane 中工作.有人可以告诉我我在这里做错了什么吗?我希望能够单击链接和浏览器以打开该页面.提前致谢.:D
I'm having a difficult time getting the hyperlink to work in a JEditorPane. Could someone please tell me what I'm doing wrong here? I want to be able to click on the link and the browser to open to that page. Thanks in advance. :D
bottomText.setText("<a href="http://www.yahoo.com">Yahoo</a>");
bottomText.setEditable(false);
bottomText.setOpaque(false);
bottomText.setEditorKit(JEditorPane.createEditorKitForContentType("text/html"));
bottomText.addHyperlinkListener(new HyperlinkListener() {
public void hyperlinkUpdate(HyperlinkEvent e) {
if(e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
}
if(Desktop.isDesktopSupported()) {
try {
Desktop.getDesktop().browse(e.getURL().toURI());
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (URISyntaxException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
});
推荐答案
哇,那比我简单多了 :P
Wow, that was simpler then I though :P
// Move this
//bottomText.setText("<a href="http://www.yahoo.com">Yahoo</a>");
bottomText.setEditable(false);
bottomText.setOpaque(false);
bottomText.setEditorKit(JEditorPane.createEditorKitForContentType("text/html"))
// To Here
bottomText.setText("<a href="http://www.yahoo.com">Yahoo</a>");
哦,等到用户点击链接再打开浏览器,在我杀了你之前有大约 4 个窗口正在运行;)
Oh, and wait till the user has clicked the link before opening the browser, had about 4 windows going before I killed you example ;)
点击更新
你快到了;)
bottomText.addHyperlinkListener(new HyperlinkListener() {
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
if (Desktop.isDesktopSupported()) {
try {
Desktop.getDesktop().browse(e.getURL().toURI());
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (URISyntaxException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
}
});
这篇关于JEditorPane 超链接摆动 html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文