Java Reference
In-Depth Information
Figure 5-9. Reversi user interface with title, background, and scores
Try resizing the window and notice that the BorderPanel keeps the components' edge aligned and automatically
resizes them to fill all available space. This combined example demonstrates how bind and the built-in layouts can be
used to compose dynamic layouts in JavaFX easily.
Creating Custom Regions
In previous sections we have made use of the Region class to provide simple styled backgrounds for our application,
but the Region class underlies all of the JavaFX layouts and is capable of much more than just this.
In this section we show you how to create custom Regions in JavaFX that are fully resizable to build the Reversi
playing pieces and squares that make up the game board. In the following section we show you how to build dynamic
containers from scratch to take these resizable nodes and use the final layout, GridPane , to construct a dynamic
playing board that resizes both the squares and the playing pieces.
Building a Custom Square Region
The foundation class of all the JavaFX layouts is the Region . It has standard functions on it to get bounds preferences
for layout and also variables to set the width and height of the Node . In this section we show you how you can build a
Reversi board square that dynamically responds to height and width changes by extending Region . The Region class
has ten properties that you can use to control the dimensions and layout, as shown in Table 5-7 .
 
Search WWH ::




Custom Search