I have Borderpane as homePane (its fxml file is home.fxml). At first in center of homePane i have a HBox which contains a button called delivery. When the user clicks this button, the center of homePane switchs to display the list of customers. It works !
The code of homeController :
public class HomeController {
@FXML
private BorderPane homePane;
@FXML
public void deliveryBtnClicked (){
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fragments/customers.fxml"));
homePane.getChildren().remove(homePane.getCenter());
try {
Pane pane = loader.load();
homePane.setCenter(pane);
}catch (IOException e){
System.out.println(e.getMessage());
}
}
public BorderPane getHomePane() {
return homePane;
}
}
The new Pane contains the table of customers and a button called order. It has own Controller :
public class CustomerController {
@FXML
public void loadOrderView() throws IOException {
Customer customer = customerTable.getSelectionModel().getSelectedItem();
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("/home.fxml"));
loader.load();
HomeController homeController = loader.getController();
BorderPane homePane = homeController.getHomePane();
homePane.getChildren().remove(homePane.getCenter());
System.out.println(homePane.getCenter());
FXMLLoader loader1 = new FXMLLoader(getClass().getResource("/fragments/order.fxml"));
Pane orderView = loader1.load();
homePane.setCenter(orderView);
System.out.println(homePane.getCenter());
}
}
When user clicks the button order, the order-view have to be loaded in the center of homePane. the print command shows that the homePane center after removed is null and then after loaded gets new view.
null
AnchorPane@755b1503
But in running Programm its doen't show the order view. I have set onAction of button order to loadOrderView. This is definitive not the problem.