我不是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是窗格的名稱。從您的點擊處理程序調用此方法。 –