2
votes

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.

3
post some code of your tryings, then we can find the error! - Tobi
@Tobi I can't figure out how to make them grow. Just placing 2 VBoxes in an HBox makes them stick to the left with minimal size. - NightRa
Try to give them some Width Values hBox.setPrefWidth(400);vbox.setPrefWidth(hbox.getPrefWidth()/2) - Tobi
@Tobi You suggest binding the widths to half the size? That would definitely work, but feels a bit forceful. Isn't there a solution using just containers? - NightRa
I m not quite sure, but you can also do setPrefWidth(Integer.MAX_VALUE) and they will take as much space as they can get - Tobi

3 Answers

1
votes

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>
0
votes

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.

0
votes

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