Java Reference
In-Depth Information
14.10.2
GridPane
A
GridPane
arranges nodes in a grid (matrix) formation. The nodes are placed in the speci-
fied column and row indices. The class diagram for
GridPane
is shown in FigureĀ 14.18.
The getter and setter methods for property values
and a getter for property itself are provided in the class,
but omitted in the UML diagram for brevity.
javafx.scene.layout.GridPane
-alignment: ObjectProperty<Pos>
-gridLinesVisible:
BooleanProperty
-hgap: DoubleProperty
-vgap: DoubleProperty
The overall alignment of the content in this pane (default:
Pos.LEFT
).
Is the grid line visible? (default:
false
)
The horizontal gap between the nodes (default:
0
).
The vertical gap between the nodes (default:
0
).
+GridPane()
+add(child: Node, columnIndex:
int, rowIndex: int): void
+addColumn(columnIndex: int,
children: Node...): void
+addRow(rowIndex: int,
children: Node...): void
+getColumnIndex(child: Node):
int
+setColumnIndex(child: Node,
columnIndex: int): void
+getRowIndex(child:Node): int
+setRowIndex(child: Node,
rowIndex: int): void
+setHalighnment(child: Node,
value: HPos): void
+setValighnment(child: Node,
value: VPos): void
Creates a
GridPane
.
Adds a node to the specified column and row.
Adds multiple nodes to the specified column.
Adds multiple nodes to the specified row.
Returns the column index for the specified node.
Sets a node to a new column. This method repositions the node.
Returns the row index for the specified node.
Sets a node to a new row. This method repositions the node.
Sets the horizontal alignment for the child in the cell.
Sets the vertical alignment for the child in the cell.
F
IGURE
14.18
GridPane
lays out nodes in the specified cell in a grid.
Listing 14.11 gives a program that demonstrates
GridPane
. The program is similar to the
one in Listing 14.10, except that it adds three labels and three text fields, and a button to the
specified location in a grid, as shown in FigureĀ 14.19.
F
IGURE
14.19
The
GridPane
places the nodes in a grid with a specified column and row
indices.
L
ISTING
14.11
ShowGridPane.java
1
import
javafx.application.Application;
2
import
javafx.geometry.HPos;
3
import
javafx.geometry.Insets;
Search WWH ::
Custom Search