@FXML
private StackPane acContent;
@FXML
private void btnSupplierOnClick(ActionEvent event) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader();
fxmlLoader.load(getClass().getResource(/view/application/supplier/ViewSupplierList.fxml").openStream());
AnchorPane acPane = fxmlLoader.getRoot();
ViewSupplierListController supplierListController = fxmlLoader.getController();
// Passing data to the supplierListController
supplierListController.setData(userNameMedia,rootPane,acContent,acMain);
acContent.getChildren().clear();
acContent.getChildren().add(acPane);
}
With the setData function i m passing values to the controller but this happens after the controller has been loaded.ASKER
ASKER
private StackPane acContent;
@FXML
private void btnSupplierOnClick(ActionEvent event) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/view/application/supplier/ViewSupplierList.fxml"));
// Create a controller instance
ViewSupplierListController supplierListController = new ViewSupplierListController(userNameMedia,rootPane,acContent);
// Set it in the FXMLLoader
fxmlLoader.setController(supplierListController);
AnchorPane acPane = fxmlLoader.load();
acContent.getChildren().clear();
acContent.getChildren().add(acPane);
}
2) Remove the fx:controller= .....public ViewSupplierListController(UserNameMedia data, StackPane rootPane,StackPane acContent) {
this.userNameMedia = data;
this.rootPane = rootPane;
this.acContent = acContent;
}
The mistake i did was instead ofAnchorPane acPane = fxmlLoader.load();
i still used:Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.
TRUSTED BY
Did you use the first example? The second one is wrong, I think