The distance between the boundaries between the boundaries

Can I set the distance between nodes on a BorderPane ? The Swing equivalent would be hgap and vgap on BorderLayout .

I did not find anything in the documentation, and the only viable workaround I can think of is to selectively set fields on child nodes to replicate the effect.

+6
source share
2 answers
 Insets insets = new Insets(10); BorderPane bp = new BoderPane() Node topNode = new Label("TOP"); bp.setTop(topNode); BorderPane.setMargin(topNode, insets); Node centerNode = new Label("CENTER"); bp.setTop(centerNode); BorderPane.setMargin(centerNode, insets); Node bottomNode = new Label("BOTTOM"); bp.setTop(bottomNode); BorderPane.setMargin(bottomNode, insets); 

Be aware: this will result in a distance between 20 (10 above and 10 from the center) between the top and the center. Similarly for the distance between the center and the bottom.

Documentation

public static void setMargin (Node child, insert value)

Sets the value of a field for a child when it is on the border. If set, the border panel will be located with the field space around it. Setting the value to null will remove the restriction.

+1
source

You can install the add-on:

In JFX:

 <BorderPane> <padding> <Insets top="10" right="10" bottom="10" left="10"/> </padding> </BorderPane> 

In code:

 @FXML private BorderPane borderPane; ... this.borderPane.setPadding(new Insets(10, 10, 10, 10)); 
-2
source

All Articles