Java Reference
In-Depth Information
}
initBoard();
turn.setValue(Owner.BLACK);
}
After running the completed application you will have a fully functional Restart button that is anchored to the
top-right corner, as shown in Figure 5-14 .
Figure 5-14. Reversi application with a Restart button anchored to the top-right corner
When to Use Different Layouts
The combination of different layout techniques discussed throughout this chapter creates a very powerful capability
for creating dynamic layouts. However, inasmuch as there are so many ways to accomplish the same results, it can
often be confusing as to what the best practice is when creating new layouts. In this section, we discuss the benefits
and disadvantages of each layout in different situations to help you more easily ascertain which best suits your
application needs.
Binding was the first technique described, and it is powerful enough to construct virtually any dynamic UI you
can imagine. However, bind has two primary drawbacks:
Complexity . The more nodes in the UI, the more edges and constraints each one must adhere
to to show up in the right location.
Performance . Although JavaFX is very efficient about how it evaluates bind statements,
too many bound variables will result in reduced performance, and also display artifacts
on resizing.
That is where the built-in layouts, HBox , VBox , FlowPane , StackPane , TilePane , GridPane , and AnchorPane , come in.
For the common case where a series of Nodes are stacked horizontally or vertically, using a box layout will result in less
complex code than the equivalent bind. Also, unlike bind, layout containers are evaluated only once per display cycle,
so you are guaranteed consistent performance regardless of the complexity of your UI.
 
Search WWH ::




Custom Search