Java Reference
In-Depth Information
Chapter 2
Creating a User Interface in JavaFX
Life is the art of drawing without an eraser.
—John W. Gardner
Chapter 1 gave you a jump start using JavaFX by covering the basics in developing and executing JavaFX programs.
Now we cover many of the details about creating a UI in JavaFX that were glossed over in Chapter 1. First on the
agenda is to get you acquainted with the theater metaphor used by JavaFX to express UIs and to cover the significance
of what we call a node-centric UI .
Programmatic Versus Declarative Creation of the User Interface
The JavaFX platform provides two complementary ways for creating a UI. In this chapter, we discuss how you can use
the Java API to create and populate a UI. This is a convenient way for Java developers who are used to writing code to
leverage APIs.
Designers often use graphical tools that allow them to declare rather than program a UI. The JavaFX platform
defines FXML, which is an XML-based markup language that can be used to declaratively describe a UI. Furthermore,
a graphical tool called SceneBuilder is made available by Oracle, and this tool is capable of working with FXML files.
The use of SceneBuilder is demonstrated in Chapter 3.
Note that parts of a UI can be created using the API, where other parts can be created using SceneBuilder. The FXML
APIs provide the bridge and the integration glue between the two approaches.
Introduction to Node-Centric UIs
Creating a UI in JavaFX is like creating a theater play, in that it typically consists of these very simple steps:
1.
Create a stage on which your program will perform. The realization of your stage will
depend on the platform on which it is deployed (e.g., a desktop, a tablet, or an embedded
system).
2.
Create a scene in which the actors and props (nodes) will visually interact with each other
and the audience (the users of your program). Like any good set designer in the theater
business, good JavaFX developers endeavor to make their scenes visually appealing.
To this end, it is often a good idea to collaborate with a graphic designer on your
“theater play.”
 
Search WWH ::




Custom Search