我不是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);
}
}
}
谢谢你的回答。我的问题是如何在borderpane左侧的按钮上放置一个动作,以在borderpane的CENTER中显示一个fxml文件设计。我正在使用borderpane作为根窗格。 – rizal
然后使用borderPane.setCenter(节点)而不是middlePane.getChildren()。setAll()假设borderPane是窗格的名称。从您的点击处理程序调用此方法。 –