Reputation: 1365
GridPane.setConstraints(button1,0,0);
GridPane.setConstraints(button2,0,1);
GridPane.setConstraints(button3,0,2);
gridPane.getChildren().addAll(button1,button2,button3);
I have some buttons in a GridPane as they are shown above, and I want to
gridPane
; Currently the buttons are aligned to the left and they don't look so good. Can someone please tell me what to do? Thanks
Upvotes: 0
Views: 154
Reputation: 49185
You can set the vertical and horizontal alignments of each cell by using other constraint options:
GridPane.setConstraints( b1, 0, 0, 1, 1, HPos.CENTER, VPos.CENTER );
GridPane.setConstraints( b2, 0, 1, 1, 1, HPos.CENTER, VPos.CENTER );
GridPane.setConstraints( b3, 0, 2, 1, 1, HPos.CENTER, VPos.CENTER );
You may also set the gaps between the cells with:
gridPane.setVgap( 10 );
gridPane.setHgap( 10 );
to debug those values visually use:
gridPane.setGridLinesVisible( true );
Upvotes: 1