I've got a JEditorPane that is correctly displaying HTML hyperlinks, but all it does is display them, how can I make it so that when someone clicks on this hyperlink, it opens up their default web browser and opens the correct page?
This is the code I have so far:
The JEditorPane is called LinksList, it reads HTML code from a file called links.txt and then displays it, with the standard blue colour and underlining...c an anyone suggest what the code might be?
This is the code I have so far:
Code:
public interface HyperLinkListener {
public void hyperlinkUpdate(HyperlinkEvent e);
}
public void hyperlinkUpdate(HyperlinkEvent evt) {
if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
try {
LinksList.setPage("http://www.facebook.com");
}
catch (Exception e) {
}
}
}
private void links(){
LinksList.addHyperlinkListener(this);
String[] linksarray = new String[10];
int i = 0;
LinksList.setContentType("text/html");
try{
BufferedReader links = new BufferedReader (new FileReader("links.txt"));
while(i<10){
linksarray[i] = links.readLine();
i++;
}//end while
i=0;
while(linksarray[i]!=null){
LinksList.setText(linksarray[i]+"\n");
i++;
}//end while
}//end try
catch (FileNotFoundException e){
errorMessageDialogue(e.getMessage());
}//end catch
catch (IOException e){
errorMessageDialogue(e.getMessage());
}//end catch
}//end links
Comment