【问题标题】:How to load locally stored page to WebView controll?如何将本地存储的页面加载到 WebView 控件?
【发布时间】:2016-09-26 16:40:08
【问题描述】:

我的应用程序中有 WebView 控件。

private WebView webview = new WebView();

我是这样用的

webview.getEngine().load("http://google.com/");

它运行良好,但我如何使用它来加载本地存储的页面。 例如:

webview.getEngine().load("file:myLocallyStoredPage.html");

【问题讨论】:

  • 你试过"file:///yourfile.html"
  • 是的。此外,我使用类似的路径来加载图像: new ImageView(new Image("file:red_arrow.png"));

标签: java javafx webview


【解决方案1】:

您可以创建一个URL 以从FilePath 传递给WebEngine

File file = ...
URL url = file.toURI().toURL();
Path path = ...
URL url = path.toUri().toURL();
webview.getEngine().load(url.toExternalForm());

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-21
    • 1970-01-01
    相关资源
    最近更新 更多