Gram Holo Gram Holo - 1 year ago 111
Java Question

JavaFX adding and removing node from BorderPane

I want to programmatically add and remove side menu in border pane.
Problem is when I add node, it is not visible.
BorderPane and StackPane are defined in FXML file.

I want to do something like this:

StackPane temp = (StackPane) borderPane.getChildren().get(1);
borderPane.getChildren().add(0, temp);

I have tried
but it is not working.

Answer Source

You can use setRight or setLeft, setTop, setBottom, setCenter methods to add Nodes to different parts and also getRight, getLeft, getTop, getBottom, getCenter to retrieve the currently assigned Node. The set methods can be also used to remove the currently set Node by passing null value.


Imagine that you have a BorderPane that has a StackPane placed on the right side, and you want to move it to the left side.

StackPane temp = (StackPane) borderPane.getRight(); // Casting is unnecessary

BorderPane Documentation on SO

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download