我正在编写 JavaFX 程序(版本 17)。 我有一个主视图,它的基本节点是一个 GridPane。在运行时,我在第 1 列 - 第 0 行的主视图内添加了另一个 GridPane,但是当父网格变大时(当我在运行时修改窗口的大小时),这个子网格没有调整大小。这是主视图:
<GridPane fx:id="mainGrid" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="800.0" prefWidth="1300.0" stylesheets="@../atlantafx_css/nord-dark.css" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="MainView.MainView">
<columnConstraints>
<ColumnConstraints hgrow="ALWAYS" maxWidth="100.0" minWidth="0.0" prefWidth="100.0" />
<ColumnConstraints halignment="CENTER" hgrow="ALWAYS" minWidth="10.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" valignment="CENTER" vgrow="ALWAYS" />
</rowConstraints>
<children>
...
</children>
</GridPane>
和子网格:
<GridPane alignment="CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" stylesheets="@../atlantafx_css/nord-dark.css" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="PCAView.PCAView">
<columnConstraints>
<ColumnConstraints halignment="CENTER" hgrow="ALWAYS" maxWidth="400.0" minWidth="400.0" />
<ColumnConstraints halignment="CENTER" hgrow="ALWAYS" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="269.0" vgrow="ALWAYS" />
<RowConstraints minHeight="10.0" prefHeight="331.0" valignment="CENTER" vgrow="ALWAYS" />
</rowConstraints>
<children>
...
</children>
</GridPane>
目的是将子网格添加到主网格的代码:
GridPane parentNode = ... // retrieving the view with FXMLLoader
mainGrid.add(parentNode, 1, 0);
mainGrid.layout();
我该怎么办?