【发布时间】:2015-12-04 09:40:22
【问题描述】:
我试图在 JavaFX WebView 组件中显示一个网站,但它只呈现一个空页面。我已将所有内容设置如下:
MainController.java
public class MainController extends Application
{
private Stage primaryStage;
private Pane pane;
@Override
public void start(Stage primaryStage)
{
// ... Some proxy config here ...
this.primaryStage = primaryStage;
this.primaryStage.setTitle("Desmon");
initRootLayout();
}
public void initRootLayout()
{
try
{
FXMLLoader loader = new FXMLLoader();
loader.setLocation(MainController.class.getResource("../view/Main.fxml"));
pane = (Pane) loader.load();
Scene scene = new Scene(pane);
primaryStage.setScene(scene);
primaryStage.show();
MainViewController controller = loader.getController();
controller.setMain(this);
}
catch(IOException e)
{
e.printStackTrace();
}
}
public Stage getPrimaryStage()
{
return primaryStage;
}
public static void main(String[] args)
{
launch(args);
}
}
MainViewController.java
public class MainViewController
{
@FXML
private WebView webTEA;
private MainController main;
public MainViewController()
{
}
@FXML
private void initialize()
{
webTEA = new WebView();
WebEngine we = webTEA.getEngine();
we.load("http://this/is/my/url.php");
}
public void setMain(MainController main)
{
this.main = main;
}
}
Main.fxml
<Pane minHeight="500.0" minWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="view.MainViewController">
和
<children>
<WebView fx:id="webTEA" layoutX="14.0" layoutY="14.0" prefHeight="417.0" prefWidth="570.0" />
</children>
如您所见,我还使用System.setProperty() 设置了一些代理设置。我也在没有特定代理设置的情况下尝试过 - 我认为这不是问题。
我不知道我做错了什么。如果我启动应用程序,我可以看到 WebView 组件,但没有内容。我只能右键单击并在上下文菜单中看到“重新加载”项。
提前致谢。
【问题讨论】:
-
如果您使用没有安全设置的普通网址(如stackoverflow.com),它是否有效?如果您使用
-Djavax.net.debug=all启动应用程序,您是否尝试过查看日志输出?见docs.oracle.com/javase/7/docs/technotes/guides/security/jsse/… -
谢谢。问题是我没有使用 FXMLLoader 注入的 WebView。