Hyperlink

try {
    String url = "http://java.sun.com";
    JEditorPane editorPane = new JEditorPane(url);
    editorPane.setEditable(false);
    editorPane.addListener(new MyListener());
} catch (IOException e) {
}

class MyListener implements Listener {
    public void hyperlinkUpdate(Event evt) {
        if (evt.getEventType() == Event.EventType.ACTIVATED) {
            JEditorPane pane = (JEditorPane)evt.getSource();
            try {
                // Show the new page in the editor pane.
                pane.setPage(evt.getURL());
            } catch (IOException e) {
            }
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.