0

I wish to create an 2x2 gridpane, where all child buttons are 25% of the GridPane. When I fill the StackPane with the GridPane, the children buttons extend past the constraints. The children buttons only snap to their positions after I resize the window.

<VBox fx:id="answerableList" styleClass="pane-with-border" minWidth="340" prefWidth="340" VBox.vgrow="ALWAYS">
          <padding>
            <Insets top="10" right="10" bottom="10" left="10" />
          </padding>
          <StackPane fx:id="answerableListPanelPlaceholder" VBox.vgrow="ALWAYS"/>
</VBox>
answerableListPanelPlaceholder.getChildren().add(answersGridPane.getRoot());
<GridPane fx:id="cardPane" maxWidth="Infinity" maxHeight="Infinity"
          xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
          alignment="center" >
    <columnConstraints>
        <ColumnConstraints hgrow="ALWAYS" minWidth="10.0" percentWidth="50.0"/>
        <ColumnConstraints hgrow="ALWAYS" minWidth="10.0" percentWidth="50.0"/>
    </columnConstraints>

    <rowConstraints>
        <RowConstraints vgrow="ALWAYS" minHeight="10.0" percentHeight="50.0"/>
        <RowConstraints vgrow="ALWAYS" minHeight="10.0" percentHeight="50.0"/>
    </rowConstraints>

    <children>
        <Button styleClass="option-label" fx:id="option1" text="\$option1" wrapText="true"
               GridPane.columnIndex="0" GridPane.rowIndex="0">
        </Button>

        <Button styleClass="option-label" fx:id="option2" text="\$option2" wrapText="true"
               GridPane.columnIndex="1" GridPane.rowIndex="0">

        </Button>

        <Button styleClass="option-label" fx:id="option3" text="\$option3" wrapText="true"
               GridPane.columnIndex="0" GridPane.rowIndex="1">

        </Button>
        <Button styleClass="option-label" fx:id="option4" text="\$option4" wrapText="true"
               GridPane.columnIndex="1" GridPane.rowIndex="1">
        </Button>
    </children>

</GridPane>

Before resizing: https://ibb.co/p0q14KC

After resizing: https://ibb.co/Wnm3HRh

JXKENG
  • 89
  • 3
  • 10
  • [mcve] please .. – kleopatra Oct 30 '19 at 06:06
  • More precisely: When does the second snippet happen in relation to creating/showing the scene? Can you reproduce the issue without your css style? If not add a minimal version of the css that still allows to reproduce the issue. – fabian Oct 30 '19 at 06:48

0 Answers0