I'm kinda new to JavaFx, for my application I need to set an indeterminate bunch of buttons on a part of the screen. Since I don't know how many buttons I'll need until the program is started, I thought on set a ScrollPane to this part of the screen, and there add dynamically a bunch of HBox containing the buttons (I use a List<> of buttons and a List<> of HBox, so I can create a new HBox for each 8 buttons).
The idea is use the ScrollPane to scroll between the different HBox which contains the buttons, so I don't need to always show all buttons. The problem is that it seems that you can't add directly a bunch of HBox to a ScrollPane. Is there anyway to perform this?? My code will be something like this:
public void startApp(int nDetect){
this.primaryStage = new Stage();
this.nDetect = nDetect;
BorderPane bp = new BorderPane();
Group root = new Group();
.
.
.
LinkedList<Button> buttons = new LinkedList<>();
LinkedList<HBox> boxes = new LinkedList<>();
for(int i=0; i<this.nDetect; i++) {
if(i%8 == 0){
boxes.add(new HBox());
boxes.get(i/8).setSpacing(5);
}
boxes.get(i/8).getChildren().add(buttons.get(i)) //add the button to the appropriate HBox
}
ScrollPane spane = new ScrollPane();
for( HBox h : boxes){
//add every element in "boxes" to the ScrollPane
}
bp.setTop(spane);
root.getChildren().add(bp);
}