简体   繁体   中英

Javafx gridpane layout allignment

I have a small question. I am trying to create a good GUI (which you can resize) with JavaFX 2.0 but I have a small problem. I am using a gridpane but when i put multiple buttons in it and when I resize the screen to a smaller size the buttons will slide into each other at the left size of the screen. Can I set a minimum size for a cell or something, I am using an FXML for the design. Thank you very much!

You can set the minimum width of a column by specifying a set of ColumnConstraints objects on the GridPane .

For example, something like:

<GridPane hgap"5" vgap="5">
<Label text="First Name:" GridPane.rowIndex="0" GridPane.columnIndex="0" />
<TextField GridPane.rowIndex="0" GridPane.columnIndex="1" />

<Label text="Last Name:" GridPane.rowIndex="1" GridPane.columnIndex="0" />
<TextField GridPane.rowIndex="1" GridPane.columnIndex="1" />

<columnConstraints>
<ColumnConstraints minWidth="100" halignment="RIGHT" />
<ColumnConstraints minWidth="150" halignment="LEFT" />
</columnConstraints>

</GridPane>

You can similarly control the layout of the rows, if desired.

See the Javadocs for GridPane and ColumnConstraints to see other properties that can be controlled this way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM