简体   繁体   中英

How to display HTML document in JavaFX WebView

I have created a webview and I am trying to load an html document from my local machine, located in the project src folder. But when I try and load it nothing happens, I also tried loading it as content. Any ideas on why this is and how to fix it.

    final WebView wv = new WebView();
    final WebEngine we = wv.getEngine();
    we.load("test.html");

Do it like this

 File f = new File("C:\\Users\\User_Name\\Desktop\\test.html");
    try {
        webView.getEngine().load(f.toURI().toURL().toString());
    } catch (MalformedURLException ex) {
        Logger.getLogger(TestWeb.class.getName()).log(Level.SEVERE, null, ex);
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM