As your application grows in complexity, so you will find it tedious and (most importantly) imprecise to arrange your visual nodes directly using their x
and y
coordinates. This recipe shows you how to use JavaFX's built-in support for layout managers to arrange visual components on the screen.
As of version 1.2, JavaFX comes with several layout managers and each provides a different way of arranging visual nodes on the screen. You will find the layout managers in package javafx.scene.layout
. Of course, you must know how to create an application in order to use a layout manager. See the recipe Building a JavaFX application for background information.
The following code snippet uses the the HBox
and along with the VBox
layout managers. The full code listing is available in ch02/source-code/src/layout/LayoutDemo.fx
.
Scene { content: HBox { width: 400 spacing: 20 hpos: HPos.LEADING content: [ VBox { spacing: 5 nodeHPos: HPos.CENTER...