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 Stage class, 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 Screen class, 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 Scene class 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 Node class 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 of Node. Take a moment to look at the variables and functions in the Node class to appreciate the capabilities provided to all of its subclasses, including bounds calculation and mouse and keyboard event handling.

  • The Group class is a subclass of the Node class. 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.image package 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.shape package 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.text package contains the Text class for drawing text in the scene. * The Font class enables you to specify the font name and size of the text.

  • The javafx.scene.media package has classes that enable you to play media. The MediaView class is a subclass of Node that displays the media.

  • The javafx.scene.chart package has classes that help you easily create area, bar, bubble, line, pie, and scatter charts. The corresponding UI classes in this package are AreaChart, BarChart, BubbleChart, LineChart, PieChart, and ScatterChart.

Here are some other packages in the JavaFX 8 API.

  • The javafx.scene.control package contains several UI controls, each one having the ability to be skinned and styled via CSS.

  • The javafx.scene.transform package enables you to transform nodes (scale, rotate, translate, shear, and affine).

  • The javafx.scene.input package contains classes such as MouseEvent and KeyEvent that provide information about these events from within an event handler function such as the Node class’s onMouseClicked event.

  • The javafx.scene.layout package contains several layout containers, including HBox, VBox, BorderPane, FlowPane, StackPane, and TilePane.

  • The javafx.scene.effect package contains easy-to-use effects such as Reflection, Glow, Shadow, BoxBlur, and Lighting.

  • The javafx.scene.web package contains classes for easily embedding a web browser in your JavaFX applications.

  • The javafx.animation package contains time-based interpolations typically used for animation and convenience classes for common transitions.

  • The javafx.beans, javafx.beans.binding, javafx.beans.property, and javafx.beans.value packages 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 `HelloEarthRise example earlier in this chapter.

  • The javafx.print package contains utilities for printing (parts of) the layout of a JavaFX application.

  • The javafx.embed.swing package contains the required functionality for embedded JavaFX applications in a Swing application.

  • The javafx.embed.swt package contains 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.