EerlijkeDame
EerlijkeDame

Reputation: 507

How to set the padding of a single BorderPane region in javafx

I have created a borderpane with javafx and use two regions: center and top. I'd like to set padding to the top region only.

myBorderPane.setPadding(Insets value) won't do, because this also sets the padding for the center region. I want to set it for the top region ONLY. Is there a way to do this?

I know I could just add another pane like a VBox to the top region and set the padding for that. Just wondering if there is a way to give the region a padding without having to add this VBox.

Upvotes: 1

Views: 5240

Answers (1)

fabian
fabian

Reputation: 82461

You can use the static void setMargin(Node child, Insets value) method to do this:

BorderPane borderPane = ...
Node top = ...
Insets topInsets = ...
borderPane.setTop(top);

BorderPane.setMargin(top, topInsets);

Upvotes: 2

Related Questions