Reputation: 1
I'm trying to center a button in JavaFX using Gridpane. I was told to use colspan and rowspan, but I can't figure out how those work.
pane.add(label1, 0, 1);
pane.add(text1, 1, 1);
pane.add(radioButton1, 0, 2);
pane.add(radioButton2, 1, 2);
pane.add(label2, 0, 3);
pane.add(text2, 1, 3);
pane.add(button, 0, 4); //What I'm trying to span.
This is what I have, and This is where I want the button to be.
Upvotes: 0
Views: 532
Reputation: 13858
I originally thought you were trying to center each line. After seeing James_D's comment, it seems that you are only having an issue with the calculate Button
.
For that try:
pane.add(button, 0, 4, 2, 1); //add(Node child, int columnIndex, int rowIndex, int colspan, int rowspan)
GridPane.setHalignment(button, HPos.CENTER);
Upvotes: 1