Example usage for javax.swing.event HyperlinkEvent getURL

List of usage examples for javax.swing.event HyperlinkEvent getURL

Introduction

In this page you can find the example usage for javax.swing.event HyperlinkEvent getURL.

Prototype

public URL getURL() 

Source Link

Document

Gets the URL that the link refers to.

Usage

From source file:MainClass.java

public void hyperlinkUpdate(HyperlinkEvent e) {
    try {//from   w  w  w.  ja v a 2 s.co m
        view.setPage(e.getURL());
        commandLine.setText(e.getURL().toExternalForm());
    } catch (java.io.IOException e2) {
    }
}

From source file:MainClass.java

public void hyperlinkUpdate(HyperlinkEvent e) {
    try {/*  w w  w  . j a  v a  2 s  . c om*/
        view.setPage(e.getURL());
    } catch (java.io.IOException e2) {
    }
}

From source file:ActivatedHyperlinkListener.java

public void hyperlinkUpdate(HyperlinkEvent hyperlinkEvent) {
    HyperlinkEvent.EventType type = hyperlinkEvent.getEventType();
    final URL url = hyperlinkEvent.getURL();
    if (type == HyperlinkEvent.EventType.ENTERED) {
        System.out.println("URL: " + url);
    } else if (type == HyperlinkEvent.EventType.ACTIVATED) {
        System.out.println("Activated");

        Document doc = editorPane.getDocument();
        try {/*ww  w . j a v a  2 s.c  om*/
            editorPane.setPage(url);
        } catch (IOException ioException) {
            System.out.println("Error following link, Invalid link");
            editorPane.setDocument(doc);
        }
    }
}

From source file:Main.java

public void hyperlinkUpdate(HyperlinkEvent hyperlinkEvent) {
    HyperlinkEvent.EventType type = hyperlinkEvent.getEventType();
    final URL url = hyperlinkEvent.getURL();
    if (type == HyperlinkEvent.EventType.ENTERED) {
        System.out.println("URL: " + url);
    } else if (type == HyperlinkEvent.EventType.ACTIVATED) {
        System.out.println("Activated");
        Document doc = editorPane.getDocument();
        try {/*from  w  ww  . j a v  a2  s  .c om*/
            editorPane.setPage(url);
        } catch (IOException ioException) {
            System.out.println("Error following link");
            editorPane.setDocument(doc);
        }
    }
}

From source file:Main.java

public void hyperlinkUpdate(HyperlinkEvent he) {
    HyperlinkEvent.EventType type = he.getEventType();
    if (type == HyperlinkEvent.EventType.ENTERED) {
        System.out.println(he.getURL().toString());
    } else if (type == HyperlinkEvent.EventType.EXITED) {
        System.out.println("exit");
    } else if (type == HyperlinkEvent.EventType.ACTIVATED) {
        if (he instanceof HTMLFrameHyperlinkEvent) {
            HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent) he;
            HTMLDocument doc = (HTMLDocument) pane.getDocument();
            doc.processHTMLFrameHyperlinkEvent(evt);
        } else {/*from  ww  w .  jav a  2 s.  c  o  m*/
            try {
                pane.setPage(he.getURL());
                System.out.println(he.getURL().toString());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:Main.java

private Box getEditPaneBox() {
    editorPane.setEditable(false);/*from   w ww . ja v  a  2  s  . c o m*/
    Box editorBox = Box.createHorizontalBox();
    editorBox.add(new JScrollPane(editorPane));

    editorPane.addHyperlinkListener((HyperlinkEvent event) -> {
        if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
            go(event.getURL());
        } else if (event.getEventType() == HyperlinkEvent.EventType.ENTERED) {
            System.out.println("click this link");
        } else if (event.getEventType() == HyperlinkEvent.EventType.EXITED) {
            System.out.println("Ready");
        }
    });

    editorPane.addPropertyChangeListener((PropertyChangeEvent e) -> {
        String propertyName = e.getPropertyName();
        if (propertyName.equalsIgnoreCase("page")) {
            URL url = editorPane.getPage();
            System.out.println(url.toExternalForm());
        }
    });

    return editorBox;
}

From source file:EditorPaneSample.java

public void hyperlinkUpdate(HyperlinkEvent hyperlinkEvent) {
    HyperlinkEvent.EventType type = hyperlinkEvent.getEventType();
    final URL url = hyperlinkEvent.getURL();
    if (type == HyperlinkEvent.EventType.ENTERED) {
        System.out.println("URL: " + url);
    } else if (type == HyperlinkEvent.EventType.ACTIVATED) {
        System.out.println("Activated");
        Runnable runner = new Runnable() {
            public void run() {
                // Retain reference to original
                Document doc = editorPane.getDocument();
                try {
                    editorPane.setPage(url);
                } catch (IOException ioException) {
                    JOptionPane.showMessageDialog(frame, "Error following link", "Invalid link",
                            JOptionPane.ERROR_MESSAGE);
                    editorPane.setDocument(doc);
                }/*from  w w w .  j  av a 2 s.c  o  m*/
            }
        };
        SwingUtilities.invokeLater(runner);
    }
}

From source file:Main.java

public void hyperlinkUpdate(HyperlinkEvent he) {
    HyperlinkEvent.EventType type = he.getEventType();
    if (type == HyperlinkEvent.EventType.ENTERED) {
        System.out.println(he.getURL().toString());
    } else if (type == HyperlinkEvent.EventType.EXITED) {
        System.out.println("Exited");
    } else if (type == HyperlinkEvent.EventType.ACTIVATED) {
        if (he instanceof HTMLFrameHyperlinkEvent) {
            HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent) he;
            HTMLDocument doc = (HTMLDocument) pane.getDocument();
            doc.processHTMLFrameHyperlinkEvent(evt);
        } else {/*  ww w  .  ja va  2  s  .com*/
            try {
                pane.setPage(he.getURL());
                System.out.println(he.getURL().toString());
            } catch (FileNotFoundException fnfe) {
                pane.setText("Could not open file: <tt>" + he.getURL() + "</tt>.<hr>");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:WebBrowserBasedOnJEditorPane.java

public void hyperlinkUpdate(HyperlinkEvent hle) {
    HyperlinkEvent.EventType evtype = hle.getEventType();
    if (evtype == HyperlinkEvent.EventType.ENTERED)
        lblStatus.setText(hle.getURL().toString());
    else if (evtype == HyperlinkEvent.EventType.EXITED)
        lblStatus.setText(" ");
}

From source file:Main.java

public void hyperlinkUpdate(HyperlinkEvent evt) {
    if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
        JEditorPane pane = (JEditorPane) evt.getSource();
        try {/*from   w  w w . java  2  s .c  o  m*/
            // Show the new page in the editor pane.
            pane.setPage(evt.getURL());
        } catch (IOException e) {
        }
    }
}