0

I am trying to open a link from JavaFX. However, attempting to do this purely from JavaFX is not working.

How can I do the following purely in JavaFX This is working for me using java.awt.desktop and I am looking for the same behavior use pure javaFX code.

hyperlink.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent e) {
            Desktop d = Desktop.getDesktop();
            try {
                d.browse(new URI(hyperlink.getText()));
            } catch (IOException ex) {
                Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
            } catch (URISyntaxException ex) {
                Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
            }

            //webEngine.load("www.google.com  ");
        }
    });

}

How can I open the link in JavaFX natively?

Moe
  • 1,427
  • 4
  • 34
  • 54
  • 1
    Your code blocks do completely different things: the JavaFX version loads the URL in a `WebView`, which you don't actually seem to display anywhere (so it's not really surprising that you don't see anything happen). Your AWT version displays the web page in a native browser. – James_D Jul 09 '17 at 13:26
  • Thanks James for your point. how can accomplish opening the link from JavaFX – Moe Jul 09 '17 at 13:27
  • It depends which of the two things you actually want to do. – James_D Jul 09 '17 at 13:28
  • I am trying to allow the user to click on a link that opens the default browser to visit that link. – Moe Jul 09 '17 at 13:30

0 Answers0