I want to add buttons to created HBox, in fxml. Everything has been drawn, and I'm collecting some data from database, creating buttons, but when I try to add it tho said HBox, it won't add them.
FXMLLoader myLoader = new FXMLLoader(getClass().getResource("/fxml_cart.fxml"));
AnchorPane root = (AnchorPane) myLoader.load();
Scene scene = new Scene(root);
Stage stage = new Stage();
stage.setScene(scene);
stage.resizableProperty().setValue(Boolean.FALSE);
Main.getMainStage().close();
Main.setMainStage(stage);
List<Products> productsList = MySQLOperations.getProductsListByCategory("1");
List<ProductCategory> productCategory = MySQLOperations.getProductCategoryList();
System.out.println(productCategory.size());
List<Button> listProductCategory = new ArrayList<>();
HBox listCategoryHBox = new HBox();
for (ProductCategory pc : productCategory) {
Button productCategoryBtn = new Button();
productCategoryBtn.setText(pc.getCategoryName());
// productCategoryBtn.setOnAction(value);
productCategoryBtn.setId("productCategoryBtn_" + pc.getKeyProductCategory());
productCategoryBtn.setPrefWidth(88);
productCategoryBtn.setPrefHeight(32);
listProductCategory.add(productCategoryBtn);
}
listCategoryHBox.getChildren().addAll(listProductCategory);
CartController fxmlCont = (CartController) myLoader.getController();
fxmlCont.setProducts(listCategoryHBox);
stage.show();
I even created some temp HBox, so I can somehow push it in. In CartController
are controllers for fxml_cart.fxml
, and in it is
@FXML
private HBox products;
on witch I call fxmlCont.setProducts(listCategoryHBox);