How can I load a URL into a JEditorPane from a link in that JEditorPane?

Sandip Chitale


import javax.swing.*;
import javax.swing.event.*;

...

jEditorPane.addHyperLinkListener(
  new HyperLinkListener()
  {
    public void hyperlinkUpdate(HyperlinkEvent e) {
      if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
        JEditorPane pane = (JEditorPane) e.getSource();
        if (e instanceof HTMLFrameHyperlinkEvent) {
           HTMLFrameHyperlinkEvent  evt = (HTMLFrameHyperlinkEvent)e;
           HTMLDocument doc = (HTMLDocument) pane.getDocument();
           doc.processHTMLFrameHyperlinkEvent(evt);
        } else {
           try {
             pane.setPage(e.getURL());
           } catch (Throwable t) {
             t.printStackTrace();
           }
        }
      }
   }
}

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

 

 

 

 

 


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

 

 

About | Sitemap | Contact