JavaFX FXML:加载后空白WebView

时间:2016-07-05 20:18:44

标签: java javafx webview sandbox signing

当我尝试使用webEngine.load();加载任何html或url时,我的webView只是空白。从我在这里读到的" JavaFX 2.2 WebView"好像我必须签署我的应用程序才能让它在沙箱模式之外运行。 http://docs.oracle.com/javafx/2/deployment/deploy_overview.htm#CEGJGHDA

这是导致这个问题的原因吗?

我正在使用NetBeans 8.1,在“项目设置”下,我将其作为独立运行。我一直在关注这些教程,每个教程都很顺利。 http://docs.oracle.com/javase/8/javafx/get-started-tutorial/get_start_apps.htm#JFXST804

这是我的三个文件。

FXML

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.media.*?>
<?import javafx.scene.web.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.text.*?>
<?import javafx.geometry.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="481.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <AnchorPane prefHeight="18.0" prefWidth="600.0">
         <children>
            <HBox layoutX="157.0" layoutY="14.0" prefHeight="64.0" prefWidth="287.0">
               <children>
                  <Label text="TwitchAid">
                     <font>
                        <Font size="53.0" />
                     </font>
                  </Label>
                  <ImageView fitHeight="150.0" fitWidth="38.0" pickOnBounds="true" preserveRatio="true">
                     <image>
                        <Image url="@Twitchaid-Logo.png" />
                     </image>
                  </ImageView>
               </children>
            </HBox>
         </children>
      </AnchorPane>
      <AnchorPane prefHeight="200.0" prefWidth="200.0">
         <children>
            <WebView fx:id="webView" prefHeight="405.0" prefWidth="600.0" />
         </children>
      </AnchorPane>
   </children>
</VBox>

爪哇

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package twitchauthorize;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

/**
 *
 * @author Dylan
 */
public class TwitchAuthorize extends Application {

    @Override
    public void start(Stage stage) throws Exception {
        Parent root = FXMLLoader.load(getClass().getResource("FXMLTwitchAuthorize.fxml"));
        Scene scene = new Scene(root);   
        stage.setScene(scene);
        stage.show();

        stage.setResizable(false);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }

}

Controller.java

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package twitchauthorize;

import javafx.fxml.FXML;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;

/**
 *
 * @author Dylan
 */
public class FXMLTwitchAuthorizeController {

    @FXML
    private WebView webView;

    @FXML
    private void initialize(){
        WebEngine engine = webView.getEngine();
        engine.load("http://www.google.com");
    }

}

1 个答案:

答案 0 :(得分:1)

您还没有在FXML中指定控制器,因此永远不会执行控制器的初始化方法。

将以下属性定义添加到构成FXML根元素的VBox元素中:

fx:controller="twitchauthorize.FXMLTwitchAuthorizeController"