GridPaneis without a doubt the most powerfull and flexible layout pane in JavaFX 2.0.
It lays out its children in a flexible grid of columns and rows and is very similar to Swing´s
GridBagLayoutor HTML´s table model. This approach makes this pane very well suited for any kind of form (like contact forms on a website).
You have the ability to...
Nodeto a cell (specified by column and row) in the
to let the
Nodespan multiple columns/rows
to align the
Nodein the cell it was applied to
to set horizontal or vertical grow for the
and to apply a margin to be kept around the
Nodein the cell.
GridPanealso extends to a very flexible API. You can use static class methods like
setRowSpan(node, value), or you can use convenience instance methods like
gridpane.add(node, column, row, columnSpan, rowSpan).
You don´t have to set the maximum number of columns or rows in the
GridPaneas it will grow automatically.
The size of one column is automatically determined by the widest
Nodein this column, the height of each row is determined by the tallest
Nodein the row.
GridPaneas it has to be considered for the column/row and the column span/row span of every single
Nodein order to get the layout you want.
For more complex layouts it is a very good idea to draw the layout on a piece of paper and to draw all lines for the columns and rows. This will ease development because you can diretly see in which cell you have to put each
Nodeand how many rows or columns they have to span.
Lets have a look at the first simple example: