Rohan
Rohan

Reputation: 561

Opening hyperlink from javafx

Here scenario is i just want to open the hyperlink which will navigate to help document html pages of my javafx application and these html pages are placed in the folder where my applicatons jar is present. I tried to use webview and webengine to load it but its not working and i am also not getting any exception for it.Kindly help, below is my code for the same:

@FXML
    private void handleHelpLink(ActionEvent event) {

        String driveName = LoginView.runTimeDriveName();
        String url = driveName + "/html/Pheonix Setup.html";
        webEngine.load(url);

    }

NOTE: i am using JAVAFX 2.1

UPDATED CODE:

public class HelpDoc extends Application {

    public static void main(String[] args) throws Exception {
        launch(args);
    }

    @Override
    public void start(final Stage stage) throws Exception {
        final WebView webView = new WebView();
        final WebEngine engine = webView.getEngine();
        String driveName = LoginView.runTimeDriveName();
        final String url = driveName + "/html/Pheonix Setup.html";
        System.out.println("URL="+url);
        engine.load(url);
        stage.setScene(new Scene(webView));
        stage.show();
    }
}

Upvotes: 0

Views: 1840

Answers (1)

assylias
assylias

Reputation: 328727

To load a local html file in a WebView, you need to provide a valid URL:

Path path = Paths.get("C:/file.html");
engine.load(path.toUri().toURL().toString());

using Java 7. If you use Java 6:

File f = new File("C:\\file.html");
engine.load(f.toURI().toURL().toString());

Upvotes: 2

Related Questions