Reputation: 309
I am new to javafx so i need a bit of help. I have 2 buttons in a VBox and i would like to add another button between these two buttons using only java code, how can this be done?
Any help is welcome.
Upvotes: 0
Views: 325
Reputation: 2154
Alternatively you can already have the button in place but not visible:
button2.setVisible( false );
button2.setManaged( false );
In FMXL, it would be:
<Button fx:id="button2" visible="false" managed="false" />
The setManaged method will prevent the layout from making space for the button.
Then when you want the button to be revealed you do the following:
button2.setManaged( true );
button2.setVisible( true );
Upvotes: 1
Reputation: 4602
You'll want to use the VBox.getChildren().Add() method.
vbox.getChildren().add(1, button);
The first parameter allows you to insert the button at a certain index, if you want the button to be between the first and second element, simply insert at index 1.
Upvotes: 1