Java Reference
In-Depth Information
There's more...
All nodes can listen for a multitude of event types. Beside the events shown in the recipe,
the next list shows additional event handlers that are common to all nodes. The name of the
handler gives a hint on how and when the event may be fired.
F
Keyboard
—
onKeyReleased
and
onKeyTyped
F
Mouse
—
onMouseClicked
,
onMouseDragged
,
onMouseEntered
,
onMouseExited
,
onMouseMoved
,
onMouseReleased
, and
onMouseWheelMoved
.
See also
F
Creating a JavaFX application
Arranging your nodes on stage
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.
Getting ready
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.
How to do it...
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
content: [
Polygon {
fill: Color.MAGENTA






