new to JavaFX and I’m using SceneBuilder to make a scrollingframe with a VBox inside which has infinite VBoxes inside (user can create them).
The problem is my setup doesnt work. Im using an AnchorPane with a ScrollingPane inside. The rest with this code:
public class ManagerSceneController {
@FXML
private ScrollPane ScrollingContainer;
public void initialize() {
FillScrollPane();
}
public void FillScrollPane() {
System.out.println("Führe aus");
VBox cardContainer = new VBox(10);
cardContainer.setPadding(new Insets(10));
for (int i = 1; i <= 50; i++) { // TO DO: Replace with actual loading
VBox card = CardComponent.createCard("Webseite"+i, "Username"+i, "Password"+i);
cardContainer.getChildren().add(card);
System.out.println(card);
System.out.println("Number of children in cardContainer: " + cardContainer.getChildren().size());
ScrollingContainer.setFitToWidth(true);
ScrollingContainer.setFitToHeight(true);
System.out.println("Erfolgreich ausgeführt");
}
}
}
The prints all print and it looks normal but the scrollingPane is just empty.
Card class:
public class CardComponent {
public static VBox createCard(String website, String username, String password) {
Label websiteLabel = new Label("Website: ");
Label usernameLabel = new Label("Username: ");
Label passwordLabel = new Label("Password: ");
VBox card = new VBox(10);
card.getChildren().addAll(websiteLabel, usernameLabel, passwordLabel);
card.setPadding(new Insets(10));
card.setStyle("-fx-border-color: black; -fx-border-width: 1px;");
return card;
}
}
I was expecting the scrollingPane to be filled with cards with 3 labels each and some padding in between.