Migrate from Javafx2.2 to Javafx8

偶尔善良 提交于 2019-12-21 20:25:42

问题


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 file:

<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>

Code:

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);
    }
}

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.


回答1:


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



来源:https://stackoverflow.com/questions/21051689/migrate-from-javafx2-2-to-javafx8

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!