我想顯示一個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