我想在JEditorPane中显示的一个简单网页中添加一个超链接onclick监听器。我有以下代码,但它不工作
JEditorPane jep = new JEditorPane();
jep.setEditable(false);
String currenturl="http://www.newsite.com";
try {
jep.addHyperlinkListener(this);
jep.setPage(currenturl);
}catch (IOException e) {
jep.setContentType("text/html");
jep.setText("<html>Could not load</html>");
}有没有人知道该怎么做?
发布于 2015-06-11 04:45:27
在添加侦听器之前,JEditorPane应该有EditorKit (内容类型"text/html“设置HTMLEditorKit,它可以提供处理URL点击的逻辑)。此外,JEditorPane必须不可编辑。
所以打电话给
jep.setContentType("text/html");
jep.setEditable(false);在添加监听器之前
更新:如果您想在可编辑的JEditorPane中处理链接,请检查this
https://stackoverflow.com/questions/30766917
复制相似问题