ste*_*CDP 5 javafx javafx-2 fxml
我有一个问题让我疯了几天.
我有一个GridPane,我想在单击按钮时隐藏第一行.
这是FXML文件
<VBox prefHeight="200.0" prefWidth="100.0">
<children>
<Button fx:id="buttonTest" mnemonicParsing="false" onAction="#handleButtonTestAction" text="Button" />
<GridPane fx:id="gridPaneTest" gridLinesVisible="true" layoutX="0.5" layoutY="0.5" BorderPane.alignment="CENTER">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label fx:id="labelTopLeft" text="top left">
<font>
<Font size="15.0" />
</font>
</Label>
<Label fx:id="labelTopRight" text="top right" GridPane.columnIndex="1">
<font>
<Font size="15.0" />
</font>
</Label>
<Label text="center left" GridPane.rowIndex="1">
<font>
<Font size="15.0" />
</font>
</Label>
<Label text="center right" GridPane.columnIndex="1" GridPane.rowIndex="1">
<font>
<Font size="15.0" />
</font>
</Label>
<Label text="bottom left" GridPane.rowIndex="2">
<font>
<Font size="15.0" />
</font>
</Label>
<Label text="bottom right" GridPane.columnIndex="1" GridPane.rowIndex="2">
<font>
<Font size="15.0" />
</font>
</Label>
</children>
</GridPane>
</children>
</VBox>Run Code Online (Sandbox Code Playgroud)
如果我点击按钮我会这样做
@FXML
public void handleButtonTestAction() {
labelTopLeft.setVisible(false);
labelTopRight.setVisible(false);
gridPaneTest.getRowConstraints().get(0).setMinHeight(0);
gridPaneTest.getRowConstraints().get(0).setPrefHeight(0);
gridPaneTest.getRowConstraints().get(0).setMaxHeight(0);
}
Run Code Online (Sandbox Code Playgroud)
单击按钮后,标签将按预期不可见,但第一行的高度根本不会更改.更改行约束后是否必须更新GridPane,还是还有其他事情要做?
谢谢!
| 归档时间: |
|
| 查看次数: |
6727 次 |
| 最近记录: |