Search code examples
javajavafxfxml

Java FX: Stack pane children width in percentage (FXML only)


Novice in Java FX. Trying to create the following layout:

enter image description here

I do not see the reason to use Grid Pane: maybe it's my mistake, but Grid pane is overkill for two child element. So, I selected the Stack Pane.

How can I set width of children to 50% and height to 100% of parent?


Solution

  • Don't use a StackPane; use a HBox and set the HBox.hgrow property to ALWAYS for both children:

    <HBox fillHeight="true">
       <children>
          <TextArea HBox.hgrow="ALWAYS" />
          <TextArea HBox.hgrow="ALWAYS" />
       </children>
    </HBox>