13JavaFX GUI: Part 2
Objectives
In this chapter you’ll:
Learn more details of laying
out nodes in a scene graph
Use property binding and
property listeners to perform
tasks when a control’s
property value changes.
Programmatically create
2Chapter 13 JavaFX GUI: Part 2
Self-Review Exercises
13.1 Fill in the blanks in each of the following:
a) You add multiple RadioButtons to a(n) to ensure that only one RadioButton
in a given group is selected at a time.
b) A(n) determines the size and positioning of nodes in the scene graph.
c) A(n) displays a title at its top and is a collapsible panel containing a layout
node, which in turn contains other nodes.
d) The package contains various classes for creating 2D and 3D shape nodes
that can be displayed in a scene graph.
e) A control’s event handler specifies what to do when the user drags the mouse
on the control.
f) To specify what to do when a user interacts with a RadioButton, set its event
handler.
g) Each TextField has a text property that’s returned by its textProperty method as a(n)
(package javafx.beans.property).
h) DoubleProperty method asString returns a(n) object (which is an Observ-
ableValue) that produces a String representation of the DoubleProperty.
i) Though you can individually add ListView items you’ll often bind a(n) object
to the ListView.
j) Class provides static methods for creating and manipulating observable col-
lections.
k) As the ListView displays items, it gets ListView cells from its .
l) JavaFX’s control enables you to embed web content in your JavaFX apps.
m) In a Java SE 8 update, JavaFX added to help people with visual impairments
use their devices. These features include screen-reader support, GUI navigation via the
keyboard and a high-contrast mode to make controls more readable.
13.2 State whether each of the following is true or false. If false, explain why:
a) In general, a node’s size should be defined explicitly.
b) A node’s position should be defined relative to its parent node and the other nodes in
its parent.
c) Most JavaFX layout panes use fixed positioning.
Exercises 3
e) Layout panes are container nodes that arrange their child nodes in a scene graph relative
to one another, based on their sizes and positions.
f) ToggleGroup method getToggle returns the Toggle that’s currently selected.
g) Each layout pane has a getChildren method that returns an ObservableList<Node> col-
lection containing the layout’s child nodes.
h) The only way to respond to a property change is via a property binding, which enables
a property of one object to be updated when a property of another object changes.
i) JavaFX properties are observable—when a property’s value changes, other objects can
respond accordingly.
j) Property bindings are limited to JavaFX controls.
k) In the RGBA color system, every color is represented by its red, green and blue color
values, each ranging from 0 to 255, where 0 denotes no color and 255 full color. The
alpha value (A)—which ranges from 0.0 to 1.0—represents a color’s opacity, with 0.0
being completely transparent and 1.0 completely opaque.
l) To respond to ListView selection changes, you register a listener for the SingleSelec-
tionModel’s selectedItem property.
m) To create a custom ListView cell format, you must first define a subclass of the Cell-
Format generic class (package javafx.scene.control) that specifies how to create a
ListView cell.
n) You can build JavaFX GUIs only by using Scene Builder.
o) JavaFX’s TableView control (package javafx.scene.control) displays tabular data in
rows and columns, and supports user interactions with that data.
p) You can add Labels to a GUI that describe other controls. In such cases, you should set
each Label’s describesControl property to the specific control the Label describes.
Exercises
NOTE: Solutions to the programming exercises are located in the ch12solutions folder.
Each exercise has its own folder named ex13_## where ## is a two-digit number representing
the exercise number. For example, Exercise 13.3’s solution is located in the folder ex13_03.
© 2018 Pearson Education, Inc., 330 Hudson Street, NY NY 10013. All rights reserved.