Center VBox in Pane

721 views Asked by At

I new to javaFx and using fxml to create templates. I can't manage to center a Vbox in a Pane that is too big, although I'm certain it must be quite straightforward. I also want a border around the VBox.

Can anyone help? Here is what I have:

<TitledPane text="Title" collapsible="false">
     <content>
        <GridPane hgap="10" vgap="10">
           <children>
              <VBox alignment="TOP_CENTER" spacing="10">
                  <!-- Content -->
              </VBox>
           </children>
           <columnConstraints>
              <ColumnConstraints halignment="CENTER"/>
           </columnConstraints>
           <rowConstraints>
              <RowConstraints/>
           </rowConstraints>
        </GridPane>
     </content>
  </TitledPane>

I guess the GridPane is a bad idea, but this is the way I know to have the borders as I want them.

Thanks for your time!

1

There are 1 answers

2
fabian On BEST ANSWER

I guess the GridPane is a bad idea, but this is the way I know to have the borders as I want them.

Yes it is. Using a GridPane for a single child is a overkill. Simply use a StackPane with a padding of 10:

<TitledPane text="Title" collapsible="false">
    <content>
        <StackPane>
            <padding>
                <Insets topRightBottomLeft="10"/>
            </padding>
            <children>
                <VBox alignment="TOP_CENTER" spacing="10">
                    <children>
                        <!-- Content -->
                    </children>
                </VBox>
            </children>
        </StackPane>
    </content>
</TitledPane>