Java GridPane元素最初超出边界,仅在调整窗口大小后捕捉到位
我希望创建一个2x2网格窗格,其中所有子按钮都是网格窗格的25%。当我用GridPane填充StackPane时,子按钮会超出约束。只有在我调整窗口大小后,子按钮才会捕捉到它们的位置Java GridPane元素最初超出边界,仅在调整窗口大小后捕捉到位,java,javafx,fxml,gridpane,vbox,Java,Javafx,Fxml,Gridpane,Vbox,我希望创建一个2x2网格窗格,其中所有子按钮都是网格窗格的25%。当我用GridPane填充StackPane时,子按钮会超出约束。只有在我调整窗口大小后,子按钮才会捕捉到它们的位置 <VBox fx:id="answerableList" styleClass="pane-with-border" minWidth="340" prefWidth="340" VBox.vgrow="ALWAYS"> <padding> <
<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>
调整大小之前:
调整大小后:请..更准确地说:第二个片段何时发生与创建/显示场景有关?你能在没有css风格的情况下重现这个问题吗?如果没有,添加一个最小版本的css,仍然允许重现问题。
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>