To set the GridPane child centered, you need to set the Halignment and Valignment of the child node.
In Java code, you can do something similar to:
GridPane.setHalignment(node, HPos.CENTER); // To align horizontally in the cell GridPane.setValignment(node, VPos.CENTER); // To align vertically in the cell
In FMXL, you can achieve a similar effect:
<GridPane> ... // other properties <children> <Button mnemonicParsing="false" text="Button" GridPane.halignment="CENTER" GridPane.valignment="CENTER" /> </children> </GridPane>
There is an easier way to achieve this if you want to align all the nodes of a particular column or row that will be aligned in the same order. Instead of adding halignment / valignment to a node, you can create ColumnConstraints or RowConstraints and add them to the GridPane.
<GridPane> <columnConstraints> <ColumnConstraints hgrow="SOMETIMES" halignment="CENTER" minWidth="10.0" prefWidth="100.0" /> ... // More constraints for other columns </columnConstraints> <children> <Button mnemonicParsing="false" text="Button" /> </children> </GridPane>
You can also add RowConstraints .
source share