我想显示一个java组件中的链接列表,不管它是什么组件。 通过链接我的意思是一些网站的网址。 这些链接可以点击,并打开在默认的网页浏览器中选择的URL,例如谷歌铬/火狐(我不想显示在Java网页,只有链接)。在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中获得纯文本。如何正确追加链接?
什么样的Java组件? – adarshr
真的没关系 - 可以是JTextPane,JTextArea,JEditorPane,List .. – koleS