Browse HTML file from local client in WebView


Question

I am mixing a JavaFX controls to swing application. I want to use WebView Control of JavaFX in Swing application . Can I browse the HTML files stored on the local hard disk of client as I can show with the help of JEditorPane in Java? Web View can display a web page from the internet but can it also browse the local system HTML files.

In WebView I am using the following code.

try
{ 
   final WebView webview = new WebView();
   webview.getEngine().load("http://oracle.com");
}
 catch(Exception ex)
 {
    ex.printStackTrace();
 }

My query is instead of the web page from net how can I give the local HTML file in load method?

1
2
11/21/2012 8:57:23 AM

Accepted Answer

File f = new File(..);
// ..
final WebView webview = new WebView();
webview.getEngine().load(f.toURI().toURL().toString());
13
11/21/2012 4:54:35 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon