The following thing is working for me
Project Structure
Application
|
src
|
package
|
WebViewLoadLocalFile.java
test.html
test.css
WebViewLoadLocalFile
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
public class WebViewLoadLocalFile extends Application {
@Override
public void start(Stage stage) throws Exception {
BorderPane borderPane = new BorderPane();
WebView webView = new WebView();
String url = getClass().getResource("test.html").toExternalForm();
webView.getEngine().load(url);
borderPane.setCenter(webView);
final Scene scene = new Scene(borderPane);
stage.setScene(scene);
stage.setHeight(300);
stage.setWidth(250);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
test.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Insert title here</title>
<link rel="stylesheet" href="test.css" />
</head>
<body>
Test HTML
</body>
</html>
test.css
body
{
background-color:#d0e4fe;
}