Surveying JavaFX Features
We close this chapter by surveying many of the features of JavaFX, some of which are a review for you. We do this by describing several of the more commonly used packages and classes in the Java SDK API.
The javafx.stage package contains the following:
-
The
Stageclass, which is the top level of the UI containment hierarchy for any JavaFX application, regardless of where it is deployed (e.g., the desktop, a browser, or a cell phone). -
The
Screenclass, which represents the displays on the machine in which a JavaFX program is running. This enables you to get information about the screens, such as size and resolution.
The javafx.scene package contains some classes that you’ll use often:
-
The
Sceneclass is the second level of the UI containment hierarchy for JavaFX applications. It includes all of the UI elements contained in the application. These elements are called graphical nodes, or simply nodes. -
The
Nodeclass is the base class of all of the graphical nodes in JavaFX. UI elements such as text, images, media, shapes, and controls (e.g., text boxes and buttons) are all subclasses ofNode. Take a moment to look at the variables and functions in theNodeclass to appreciate the capabilities provided to all of its subclasses, including bounds calculation and mouse and keyboard event handling. -
The
Groupclass is a subclass of theNodeclass. Its purpose includes grouping nodes together into a single coordinate space and allowing transforms (e.g., rotate) to be applied to the whole group. Also, attributes of the group that are changed (e.g., opacity) apply to all of the nodes contained within the group.
Several packages begin with javafx.scene that contain subclasses of Node of various types. Examples include the following:
-
The
javafx.scene.imagepackage contains the Image and ImageView classes, which enable images to be displayed in the Scene. The ImageView class is a subclass of Node. -
The
javafx.scene.shapepackage contains several classes for drawing shapes such as Circle, Rectangle, Line, Polygon, and Arc. The base class of the shapes, named Shape, contains an attribute named fill that enables you to specify a color, pattern, or gradient with which to fill the shape. -
The
javafx.scene.textpackage contains the Text class for drawing text in the scene. * TheFontclass enables you to specify the font name and size of the text. -
The
javafx.scene.mediapackage has classes that enable you to play media. TheMediaViewclass is a subclass of Node that displays the media. -
The
javafx.scene.chartpackage has classes that help you easily create area, bar, bubble, line, pie, and scatter charts. The corresponding UI classes in this package areAreaChart,BarChart,BubbleChart,LineChart,PieChart, andScatterChart.
Here are some other packages in the JavaFX 8 API.
-
The
javafx.scene.controlpackage contains several UI controls, each one having the ability to be skinned and styled via CSS. -
The
javafx.scene.transformpackage enables you to transform nodes (scale, rotate, translate, shear, and affine). -
The
javafx.scene.inputpackage contains classes such asMouseEventandKeyEventthat provide information about these events from within an event handler function such as the Node class’sonMouseClickedevent. -
The
javafx.scene.layoutpackage contains several layout containers, including HBox, VBox, BorderPane, FlowPane, StackPane, and TilePane. -
The
javafx.scene.effectpackage contains easy-to-use effects such as Reflection, Glow, Shadow, BoxBlur, and Lighting. -
The
javafx.scene.webpackage contains classes for easily embedding a web browser in your JavaFX applications. -
The
javafx.animationpackage contains time-based interpolations typically used for animation and convenience classes for common transitions. -
The
javafx.beans,javafx.beans.binding,javafx.beans.property, andjavafx.beans.valuepackages contain classes that implement properties and binding. -
The `javafx.fxml package contains classes that implement a very powerful facility known as FXML, a markup language for expressing JavaFX UIs in XML.
-
The
javafx.util package contains utility classes such as the Duration class used in the `HelloEarthRiseexample earlier in this chapter. -
The
javafx.printpackage contains utilities for printing (parts of) the layout of a JavaFX application. -
The
javafx.embed.swingpackage contains the required functionality for embedded JavaFX applications in a Swing application. -
The
javafx.embed.swt packagecontains the required functionality for embedding JavaFX applications in an SWT application. Take a look at the JavaFX API docs again in light of this information to get a deeper sense of how you can use its capabilities.