How do I make hyperlinks work in an HTML page displayed in a JEditorPane?

Thomas Buck

Add a hyperlinkListner to your JEditorPane instance via addHyperlinkListener().

Define a hyperlinkUpdate() method as required when adding this listener. It's basically:

editorPane.addHyperlinkListener(new HyperlinkListener() {
  public void hyperlinkUpdate(HyperlinkEvent e) {
    try {
      if (e.getEventType == HyperlinkEventType.ACTIVATED) 
    catch (IOException e) {
      // handle as you like

0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.