Java Reference
In-Depth Information
JavaFX provides many UI controls for developing a comprehensive user interface.
Key
Point
A graphical user interface (GUI) makes a system user-friendly and easy to use. Creating a
GUI requires creativity and knowledge of how UI controls work. Since the UI controls in
JavaFX are very flexible and versatile, you can create a wide assortment of useful user inter-
faces for rich Internet applications.
Oracle provides tools for visually designing and developing GUIs. This enables the program-
mer to rapidly assemble the elements of a GUI with minimum coding. Tools, however, cannot
do everything. You have to modify the programs they produce. Consequently, before you begin
to use the visual tools, you must understand the basic concepts of JavaFX GUI programming.
Previous chapters used UI controls such as
Button
,
Label
, and
TextField
. This chapter
introduces the frequently used UI controls in detail (see Figure 16.1).
GUI
Button
Node
Parent
Control
Labeled
ButtonBase
CheckBox
Covered in
Chapter 14
ScrollBar
Label
ImageView
ToggleButton
RadioButton
Slider
MediaView
TextArea
TextInputControl
TextField
PasswordField
ListView
ComboBoxBase
ComboBox
F
IGURE
16.1
These UI controls are frequently used to create user interfaces.
Note
Throughout this topic, the prefixes
lbl
,
bt
,
chk
,
rb
,
tf
,
pf
,
ta
,
cbo
,
lv
,
scb
,
sld
, and
mp
are used to name reference variables for
Label
,
Button
,
CheckBox
,
RadioButton
,
TextField
,
PasswordField
,
TextArea
,
ComboBox
,
ListView
,
ScrollBar
,
Slider
, and
MediaPlayer
.
naming convention
for controls
A
label
is a display area for a short text, a node, or both. It is often used to label other controls
(usually text fields). Labels and buttons share many common properties. These common prop-
erties are defined in the
Labeled
class, as shown in Figure 16.2.
A
Label
can be constructed using one of the three constructors as shown in Figure 16.3.
The
graphic
property can be any node such as a shape, an image, or a control. Listing 16.1
gives an example that displays several labels with text and images in the label, as shown in
Figure 16.4.
L
ISTING
16.1
LabelWithGraphic.java
1
import
javafx.application.Application;
2
import
javafx.stage.Stage;
3
import
javafx.scene.Scene;
4
import
javafx.scene.control.ContentDisplay;
5
import
javafx.scene.control.Label;
Search WWH ::
Custom Search