JavaFx GridPane - how to center elements

為{幸葍}努か 提交于 2019-11-30 18:52:25

oh, that was easy. i did the alignment on the wrong place. adding this will do the job:

tmp[currArrPos].setAlignment(Pos.CENTER);

thanks anyway.

You can use the setAligment(Pos.CENTER) property of your element-

or you can define a contraint to the GridPane that contains the elements

<columnConstraints>
    <ColumnConstraints halignment="CENTER" />
</columnConstraints>

Example:

<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.ColumnConstraints?>

<GridPane fx:controller="app.graphics.Controller"
          xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10">
    <columnConstraints>
        <ColumnConstraints halignment="CENTER" />
    </columnConstraints>
</GridPane>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!