Issue
I have a tabPane with many tabs and each of those tabs has a HBox with many VBox in the HBox.
The tabs and their HBox load at the start by looping through a database and creating them for each row and once done I want to add more VBoxs into the HBox, via a button in the menu at the top of the program. The program prompts the user for a tab and then I set the selectedTab (this.selTab) I'm adding VBox's to via this code, so I can access it as I insert them:
tabPane.getSelectionModel().select(defaultNum);
selTab = tabPane.getSelectionModel().getSelectedItem();
I also have a HBox I keep in context. When I tell the system I want to add a VBox to a HBox, the in context HBox is still set to the final HBox made for the final line of the database back when the program started. For example, if I try and put a VBox into tab 3 of 5, it will do everything fine, except it puts the VBox into tab 5 of 5 (the final tab/HBox it made on bootup). I want to change the in context HBox to the one found inside the selectedTab, so that I can direct the system to put the VBox in the correct HBox but I don't know how to access it. I thought it might have been
curHbox = selTab.getContext().getChildren();
or
curHbox = selTab.getContext().getValue();
But I got this error for either: "The method getChildren() is undefined for the type Node"
See below screenshot of the in context selectedTab, how do I access the HBox which you can see in value?
I feel it's something obvious I'm missing, but I'm new to JavaFX and everything I searched for on here wasn't what I was looking for. Also I feel like I've just said box a lot, so I hope this makes sense!
Solution
Please provide a minimal reproducible example to showcase the issue. That way someone can spot the issue and give you the fix more quickly.
Having said that, based on the info/image you gave, it looks like you are setting the HBox as the content to your tab. So to access that you can directly get the content and cast it to HBox.
Something like:
selTab = tabPane.getSelectionModel().getSelectedItem();
HBox hbox = (HBox)selTab.getContent();
hbox.getChildren().add(...);
Answered By - Sai Dandem