Java Reference
In-Depth Information
How it works...
The layout manager controls how components are arranged and laid out when rendered. A
layout manager affords developers the ability to declaratively arrange nodes without having
to worry about positional math and re-flow rules. The components are laid out according to
the rules applied by the layout managers.
The code listing for the recipe uses the HBox in conjunction with the VBox layout managers
to create the output shown in the previous screenshot. Let's examine how this works.
F Splitting up the scene —irst, the HBox layout manager is used to split the scene
horizontally into three cells (see next screenshot). This is done by placing an instance
of the HBox class as the content of the Scene . Each item added to the content of the
HBox layout manager is placed along the x-axis and is equally spaced (controlled by
the spacing property).
F Nesting layout —the items placed in the HBox content can either be a visual node or
another layout manager node (you have got to love scene graph!). This allows us to
nest an instance of VBox in each cell of the HBox , as shown in the next screenshot.
The VBox lays out its content vertically, and we use it to stack a shape and a text
node that describes the shape.
There's more...
JavaFX 1.2 offers several other managers to help developers quickly arrange nodes:
F Flow —lays out content vertically or horizontally (depending on the selected
orientation). The manager automatically flows to the next column (or row).
F Stack —this layout manager stacks its content in z-plane going from back to front.
F Tile —lays out its content uniformly vertically or horizontally, where each node
receives the same dimension in the tile (think of a HTML table).
Future versions of the platform will surely include more layout managers and options.
Search WWH ::

Custom Search