I want to display multiple Hyperlinks using JEditorPane
.To be more specific i have a HashSet
named urlLinks:
static Set<String> urlList = new HashSet<>();
and inside it I store urls like
www.google.com
www.facebook.com
etc.
As i said i am using the JEditorPane
and I set it like this:
static final JEditorPane ResultsArea = new JEditorPane();
ResultsArea.setEditorKit(JEditorPane.createEditorKitForContentType("text/html"));
ResultsArea.setEditable(false);
At some point I want to display on the JEditorPane all these links as Hyperlinks
so I do this:
for(String s : urlList)
{
s=("<a href=" +s+ ">"+s+"</a>"+"\n");
ResultsArea.setText(ResultsArea.getText()+s+"\n");
}
but it doesn't display anything. When i try to change it like this
ResultsArea.setText(s);
it displays me only one of them.However I want to display all of them one after the other like
www.example.com
www.stackoverflow.com
etc.
Does anyone know how to do that?
Use a StringBuilder
to build the list of URLs first.
StringBuilder sb = new StringBuilder();
for (String s : urlList) {
sb.append("<a href=").append(s).append(">").append(s).append("</a>\n");
}
ResultsArea.setText(sb.toString()); // then set the complete URL list once