JavaFX How to change GridPane row height programmatically

I have a problem that turned me on for a couple of days.

I have a GridPane and I want to hide the first row when I click the button.
This is an FXML file

<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> 

If I press the "I" button, I will do it

 @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); } 

After I press the button, the labels will be invisible as expected, but the height of the first line will not change at all. Should I update the GridPane after changing row restrictions or is there something else?

THANKS!

+5
source share
1 answer

Node.setVisible() simply toggles the visibility state of Node .

To exclude Node from your parent layout calculations, you must also set its managed state by calling Node.setManaged(false) .

+6
source

Source: https://habr.com/ru/post/1212601/


All Articles