2013-06-06 3 views
1

Мне нужно выложить 4 кнопки в сетке 2x2. Все кнопки должны иметь одинаковый размер и изменять его при изменении размера окна.Как расположить кнопки, чтобы они заполнили свободное пространство

Теперь я использую следующий FXML, но кнопки не меняют свой размер.

<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> 

ответ

1

Вот как мне удалось это сделать.

<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> 
0

У меня была такая же проблема с ComboBox и решил это так:

<ComboBox hgrow="ALWAYS" maxWidth="Infinity" /> 
Смежные вопросы