在JavaFX上创建母版页面(屏幕)

时间:2017-01-22 17:30:36

标签: javafx-8 fxml

当我安排javafx布局时,我遇到了一些麻烦。我使用BorderPane。顶部和左侧区域用于静态视图(页面)。我将MenuBar放在Top上,将一些Buttons放在左边,就像在图片中一样。而且,当我点击一个按钮时,内容将在中心打开。每个Button都有不同的内容和布局。 " Money Box"按钮将有TabPane作为其内容,我已使用SceneBuilder创建它。 "咖啡"按钮将有Table的内容,我使用SceneBuilder创建它。我在这里解决问题的策略是什么,或者我该做些什么呢?

[IMG] http://i.imgur.com/fG6a0kg.png[/img]

1 个答案:

答案 0 :(得分:0)

我并不是100%确定您究竟在寻找什么,并且根据您的描述,有很多方法可以满足您的需求。我有类似的行为,我们为每个选定的布局使用不同的FXML并加载它们并从场景中删除它们。

private void openMiddleNode(String view) {}
    try {
        FXMLLoader loader = new FXMLLoader();
        Parent node = loader.load(getClass().getClassLoader().getResource(view).openStream());
        //If your middle section has it's own controller (likely an instance variable, if it needs to respond to events from the parent controller)
        MyController controller = loader.getController();
        controller.anyCustomSetup();

        //Assumes that this middlePane is defined in the FXML and initialized above
        middlePane.getChildren().setAll(node);
    } catch (IOException ie){
        if(logger.isErrorEnabled()){
            logger.error("An exception has been thrown: " + ie);
        }
    }
}
相关问题