Kennedy
Kennedy

Reputation: 1

JavaFX Gridpane Layout with Colspan and Rowspan

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

Answers (1)

SedJ601
SedJ601

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

Related Questions