【发布时间】:2016-11-07 19:07:54
【问题描述】:
当我尝试使用 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>
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.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");
}
}
【问题讨论】:
-
如果那些反对我的问题的人可以告诉我他们为什么这样做,我很乐意使用这些信息来改进我的问题,这样我就不会被禁止:)
-
我还没有投反对票,但是您的问题中没有提供足够的信息来完全理解您的要求。你是如何运行你的应用程序的?如果它不是浏览器嵌入式应用程序或 webstart 应用程序,则它具有完整的系统权限,无需对代码进行签名。正如您在packaging basics 中看到的那样,打包和运行应用程序的方式有很多种,而您的操作方式会影响应用程序的权限。如果是权限错误,通常会有一个堆栈跟踪。
-
如果它是浏览器嵌入式应用程序,那将是一种奇怪的应用程序,因为您将在用于显示 html 的 web 浏览器内的 java 应用程序中嵌入用于显示 html 的 web 视图。此外,Oracle 对浏览器嵌入式应用程序的支持是 soon to be deprecated,并且已经或即将成为 no longer be supported by the browser vendors。
-
几票否决票,不会让你被禁止,你不必担心。
-
@jewelsea - 如果这有帮助,我使用的是 NetBeans 8.1,在项目设置下我将它作为独立运行。没有抛出错误,因此它可能不是权限错误。
标签: java javafx webview sandbox signing