vbezhenar
vbezhenar

Reputation: 12356

How to layout buttons so they will fill available space

I need to lay out 4 buttons in 2x2 grid. All buttons must have the same size and change it when window changes it's size.

I use the following FXML now but buttons don't change their size.

<GridPane xmlns:fx="http://javafx.com/fxml">
    <Button fx:id="btnLogin" text="Login" GridPane.rowIndex="0" GridPane.columnIndex="0"/>
    <Button fx:id="btnLibrary" text="Library" GridPane.rowIndex="0" GridPane.columnIndex="1"/>
    <Button fx:id="btnRegister" text="Register" GridPane.rowIndex="1" GridPane.columnIndex="0"/>
    <Button fx:id="btnHelp" text="Help" GridPane.rowIndex="1" GridPane.columnIndex="1"/>
</GridPane>

Upvotes: 2

Views: 1839

Answers (2)

Agyss
Agyss

Reputation: 562

I had the same problem with a ComboBox and solved it this way:

<ComboBox hgrow="ALWAYS" maxWidth="Infinity" />

Upvotes: 0

vbezhenar
vbezhenar

Reputation: 12356

That's how I managed to do it.

<GridPane xmlns:fx="http://javafx.com/fxml">
    <columnConstraints>
        <ColumnConstraints percentWidth="50"/>
        <ColumnConstraints percentWidth="50"/>
    </columnConstraints>
    <rowConstraints>
        <RowConstraints percentHeight="50"/>
        <RowConstraints percentHeight="50"/>
    </rowConstraints>
    <Button fx:id="btnLogin" text="Login" GridPane.rowIndex="0" GridPane.columnIndex="0" maxWidth="10000" maxHeight="10000"/>
    <Button fx:id="btnLibrary" text="Library" GridPane.rowIndex="0" GridPane.columnIndex="1" maxWidth="10000" maxHeight="10000"/>
    <Button fx:id="btnRegister" text="Register" GridPane.rowIndex="1" GridPane.columnIndex="0" maxWidth="10000" maxHeight="10000"/>
    <Button fx:id="btnHelp" text="Help" GridPane.rowIndex="1" GridPane.columnIndex="1" maxWidth="10000" maxHeight="10000"/>
</GridPane>

Upvotes: 1

Related Questions