本文介绍了从Javafx2.2迁移到Javafx8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Javafx2.2应用程序迁移到Javafx8.使用嵌套FXML时出现以下问题:

I am trying to migrate Javafx2.2 application to Javafx8. I am getting following issue while using nested FXML:

javafx.fxml.LoadException: Root hasn't been set.
Use method setRoot() before load.

FXML文件:

<fx:root type="javafx.scene.layout.VBox"
         xmlns:fx="http://javafx.com/fxml"
         xmlns="http://javafx.com/javafx/8"
         fx:controller="com.ui.TestController">
    <TextField fx:id="textField"/>
    <Button text="Click Me"/>
</fx:root>

代码:

FXMLLoader loader = new FXMLLoader();
loader.setResources(bundle);
InputStream in = Main.class.getClassLoader().getResourceAsStream(fxml);
loader.setBuilderFactory(new JavaFXBuilderFactory());
loader.setLocation(Main.class.getResource(fxml));
Node page = null;
try {
    page = (Node) loader.load(in);
} catch (IOException e) {
    logger.error("{}", e);
} finally {
    try {
        in.close();
    } catch (IOException e) {
        logger.error("{}", e);
    }
}

我需要page节点来设置另一个BorderPane.center.它与Javafx2.2一起使用.我在这里想念的是什么?任何帮助将不胜感激.

I need page node to set in another BorderPane.center. It works with Javafx2.2. What I am missing here? Any help would be appreciated.

推荐答案

使用<VBox></VBox>而不是<fx:root type="javafx.scene.layout.VBox"></fx:root>修复了此问题,至少适用于Javafx构建b121.

Using <VBox></VBox> instead of <fx:root type="javafx.scene.layout.VBox"></fx:root> has fixed this issue, atleast for Javafx build b121.

这篇关于从Javafx2.2迁移到Javafx8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-26 18:54