I want to display a list of links in a java component, doesn’t matter what component it is.
By links I mean URLs of some sites.
Those links can be clicked and doing so opens chosen URL in the default web browser for example google chrome / firefox ( I don’t want to display web pages in java, only links ).
I already know how to display single link, but I am having problems with display a list of links. I tried to do it like this :
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");
but it doesn’t work due to problems with “/” in the html closing tag. And I get plain text in JEditorPane. How to append links properly?
You can use html in JLabel component. That means you can use links via a-href also.