NightRa
NightRa

Reputation: 11801

JavaFX evenly split children

How can I acheive an evenly split UI, as the Player boxes demonstrate in the following example:

Desired UI

I would model it as an HBox with 2 evenly sized VBoxes, but I can't get them to stretch to the same size in the HBox.

Upvotes: 3

Views: 3626

Answers (3)

vdshb
vdshb

Reputation: 1999

Stretching VBoxes as two halves of single HBox works for me with HBox.hgrow="ALWAYS" property set for both VBoxes:

<HBox>
  <VBox HBox.hgrow="ALWAYS">
    ...
  </VBox>
  <VBox HBox.hgrow="ALWAYS">
    ...
  </VBox>
</HBox>

Upvotes: 2

James_D
James_D

Reputation: 209330

Place the two VBoxs in a TilePane instead of an HBox.

Upvotes: 0

Tobi
Tobi

Reputation: 932

Give your HBox a PrefWidth Value. Then you can bind the Widths of your VBoxes to the half of that Width

hBox.setPrefWidth(400);
vbox.setPrefWidth(hbox.getPrefWidth()/2);

You might wanna take a look at JavaFX Scene Builder. There you can Design your Layouts. Just saw using a SplitPane would also work. There you can set the DividerPosition to 0.5 (so centered). Then you can put every kind of Panes inside you like.

Upvotes: 0

Related Questions