A Dude
A Dude

Reputation: 37

Can nodes be added to an HBox during runtime?

I have a JavaFX application in which displays information that is received from a node.js server. At one point, when it receives a specific string "new_game", it should reload 4 VBoxes which are inside of an HBox. Is it possible to remove the old VBoxes and put in new ones after the program has already launched?

(FYI, I am asking this because updating the VBoxes would be kind of a hassle because of my nooby code.)

Upvotes: 0

Views: 103

Answers (1)

fuggerjaki61
fuggerjaki61

Reputation: 821

So you want to remove the old vBoxes and add new one's I would use some of this:

hBox.getChildren().clear();

would remove everthing of this hbox so if you only want to remove the 4 specific vboxes then use this:

hBox.getChildren().remove(vBox1, vBox2, vBox3, vBox4);

then you want to add the new vboxes, do it like this

hBox.getChildren().addAll(newVBox1, newVBox2, newVBox3, newVBox4);

I hope this answers your question

Upvotes: 1

Related Questions