简体   繁体   English

JavaFX WebView-未加载页面

[英]JavaFX WebView - not loading page

I have created my RootLayout inside of JavaFX Sceene builder. 我已经在JavaFX Sceene构建器中创建了RootLayout。 It containst BorderPane and in it's center TabPane with three tabs. 它包含BorderPane,并且在它的中间具有三个标签的TabPane。 On first tab I want to have WebView. 在第一个选项卡上,我想要WebView。 My RootController contains: 我的RootController包含:

      @FXML
      private WebView webview;

      @FXML 
      private WebEngine webengine;

I have conected my WebView in RootLayout.fxml by it fx:id with webview variable. 我已经将RoxLayout.fxml中的WebView通过带有Webview变量的fx:id选中了。 My initialize method in RootLayoutController is (RootLayout controler is defined in fxml file): 我在RootLayoutController中的initialize方法是(RootLayout控制器在fxml文件中定义):

   @FXML
    private void initialize() {

         this.webview = new WebView();
         this.webengine = this.webview.getEngine();
         this.webengine.load("http://www.oracle.com/us/products/index.html");

    }

But page is not loading. 但是页面未加载。 Any suggestions ? 有什么建议么 ?

This is a duplicate of other questions, but I'm not able to find them in a reasonable amount of time searching. 这是其他问题的重复,但是我无法在合理的时间内搜索到它们。

Never initialize references that are injected using @FXML . 切勿初始化使用@FXML注入的@FXML Specifically, since you have 具体来说,由于您拥有

@FXML
private WebView webview ;

it is an error to then do 然后做一个错误

this.webview = new WebView();

This creates a new instance of WebView , which is distinct from the one you defined in the FXML file. 这将创建一个新的WebView实例,该实例不同于您在FXML文件中定义的实例。 Thus when you load the page you are loading it into the new WebView instance (which is not part of the scene graph). 因此,当您加载页面时,会将其加载到新的WebView实例中(该实例不属于场景图)。

Additionally, I doubt that you are actually creating the WebEngine directly in your FXML file. 另外,我怀疑您实际上是直接在FXML文件中创建WebEngine So I think you need: 所以我认为您需要:

@FXML
private WebView webview ;

private WebEngine webengine ;

public void initialize() {
    this.webengine = this.webview.getEngine();
    this.webengine.load("http://www.oracle.com/us/products/index.html");
}

If you really do define the webengine in FXML, then you need 如果确实webengine FXML定义webengine ,那么您需要

@FXML
private WebView webview ;

@FXML
private WebEngine webengine ;

public void initialize() {
    this.webengine.load("http://www.oracle.com/us/products/index.html");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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