【发布时间】:2012-01-05 15:02:05
【问题描述】:
我想在一个 java 组件中显示一个链接列表,不管它是什么组件。 链接是指某些网站的 URL。 可以单击这些链接,然后在默认网络浏览器中打开选定的 URL,例如 google chrome / firefox(我不想在 java 中显示网页,只有链接)。
我已经知道如何显示单个链接,但是在显示链接列表时遇到了问题。我试着这样做:
public void appendTextToJEditorPane(String text) {
try {
Document doc = jEditorPane1.getDocument();
String newLine = "\n";
String url = "<html><a href=" + text + ">" + text + "<//a><//html>.";
doc.insertString(doc.getLength(), url, null);
doc.insertString(doc.getLength(), newLine, null);
} catch (BadLocationException exc) {
exc.printStackTrace();
}
}
appendTextToJEditorPane("http://google.pl");
appendTextToJEditorPane("http://wp.pl");
appendTextToJEditorPane("http://onet.pl");
但由于 html 结束标记中的“/”有问题,它不起作用。我在 JEditorPane 中得到纯文本。如何正确添加链接?
【问题讨论】:
-
没关系 - 可以是 JTextPane、JTextArea、JEditorPane、List..