Java Reference
In-Depth Information
Listing 5-13.
Wrapper Application That Displays Two Reversi Squares Side by Side with Playing Pieces on Top
public class ReversiPieceTest extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
Node white = new StackPane(new ReversiSquare(), new ReversiPiece(Owner.WHITE));
Node black = new StackPane(new ReversiSquare(), new ReversiPiece(Owner.BLACK));
HBox hbox = new HBox(white, black);
hbox.setSnapToPixel(false);
primaryStage.setScene(new Scene(hbox));
HBox.setHgrow(white, Priority.ALWAYS);
HBox.setHgrow(black, Priority.ALWAYS);
primaryStage.show();
}
}
Figure
5-11
shows the completed application with both white and black pieces displayed side by side.
Figure 5-11.
One Reversi square with a white playing piece on it, and another with a black piece
Laying Out the Tiles Using a
GridPane
One of the most flexible and powerful layouts contained in JavaFX is the
GridPane
. It lets you arrange the children
in a grid composed of rows and columns, optionally assigning constraints such as
alignment
,
grow
, and
margin
to
individual nodes or an entire row or column. You can also do advanced layouts that will span rows or columns, giving
you a layout container that is truly a superset of all the other containers discussed so far.
Table
5-9
lists the different properties of
GridPane
that you can set either per
Node
or on an entire column or row
(with the exception of
margin
).
Search WWH ::
Custom Search