Contents
Introduction
Chapter 1: Getting a Jump Start in JavaFX
A Brief History of JavaFX
Prepare Your JavaFX Journey
Required Tools
JavaFX, the Community
Use the Official Specifications
ScenicView
Packaging and Distribution
Developing Your First JavaFX Program: Hello Earthrise
Compiling and Running from the Command Line
Understanding the Hello Earthrise Program
What Happened to the Builders?
The JavaFX Application
A Stage and a Scene
Displaying Images
Displaying Text
Working with Graphical Nodes as a Group
Clipping Graphical Areas
Animating the Text to Make It Scroll Up
Building and Running the Program with NetBeans
Developing Your Second JavaFX Program: “More Cowbell! ”
Building and Running the Audio Configuration Program
The Behavior of the Audio Configuration Program
Understanding the Audio Configuration Program
The Magic of Binding
Colors and Gradients
The Model Class for the Audio Configuration Example
Using InvalidationListeners and Lambda Expressions
Surveying JavaFX Features
Summary
Resources
Chapter 2: Creating a User Interface in JavaFX
Programmatic Versus Declarative Creation of the User Interface
Introduction to Node-Centric UIs
Setting the Stage
Understanding the Stage Class
Using the Stage Class: The StageCoach Example
Understanding the StageCoach Program
Obtaining Program Arguments
Setting the Style of the Stage
Controlling Whether a Stage Is Resizable
Making a Stage Full Screen
Working with the Bounds of the Stage
Drawing Rounded Rectangles
Dragging the Stage on the Desktop When a Title Bar Isn’t Available
Using UI Layout Containers
Ascertaining Whether the Stage Is in Focus
Controlling the Z-Order of the Stage
Closing the Stage and Detecting When It Is Closed
Making a Scene
Using the Scene Class: The OnTheScene Example
Understanding the OnTheScene Program
Setting the Cursor for the Scene
Painting the Scene’s Background
Populating the Scene with Nodes
Finding a Scene Node by ID
Accessing the Stage from the Scene
Inserting a Node into the Scene’s Content Sequence
CSS Styling the Nodes in a Scene
Handling Input Events
Surveying Mouse, Keyboard, Touch, and Gesture Events and Handlers
Understanding the KeyEvent Class
Understanding the MouseEvent Class
Understanding the TouchEvent Class
Understanding the GestureEvent Class
Animating Nodes in the Scene
Using a Timeline for Animation
The Metronome1 Example
Understanding the Metronome1 Program
Understanding the Timeline Class
Inserting Key Frames into the Timeline
Controlling and Monitoring the Timeline
Using the Transition Classes for Animation
The MetronomeTransition Example
The Behavior of the MetronomeTransition Program
Understanding the MetronomeTransition Program
Using the TranslateTransition Class
Controlling and Monitoring the Transition
The MetronomePathTransition Example
The Behavior of the MetronomePathTransition Program
Understanding the MetronomePathTransition Program
Using the PathTransition Class
Drawing an Ellipse
The Zen of Node Collision Detection
Understanding the ZenPong Program
Using the KeyFrame Action Event Handler
Using the Node intersects() Method to Detect Collisions
Dragging a Node
Giving Keyboard Input Focus to a Node
Using the onKeyPressed Event Handler
Summary
Resources
Chapter 3: Using SceneBuilder to Create a User Interface
Setting the Stage with FXML
Creating a User Interface Graphically with JavaFX SceneBuilder
Understanding the FXML File
Understanding the Controller
Understanding the FXMLLoader
Understanding the FXML Loading Facility
Understanding the FXMLLoader Class
Understanding the @FXML Annotation
Exploring the Capabilities of FXML Files
The Deserialization Power of the FXML Format
Understanding Default and Static Properties
Understanding Attribute Resolutions and Bindings
Using Multiple FXML Files
Creating Custom Components Using fx:root
Event Handling Using Scripting or Controller Properties
Using JavaFX SceneBuilder
Overview of JavaFX SceneBuilder
Understanding the Menu Bar and Items
Understanding the Library Panel
Understanding the Document Panel
Understanding the Content Panel
Understanding the Inspector Panel
Summary
Resources
Chapter 4: Properties and Bindings
Forerunners of JavaFX Binding
A Motivating Example
Understanding Key Interfaces and Concepts
Understanding the Observable Interface
Understanding the ObservableValue Interface
Understanding the WritableValue Interface
Understanding the ReadOnlyProperty Interface
Understanding the Property Interface
Understanding the Binding Interface
Type-Specific Specializations of Key Interfaces
A Common Theme for Type-Specific Interfaces
Commonly Used Classes
Creating Bindings
Understanding the Bindings Utility Class
Understanding the Fluent Interface API
Understanding the JavaFX Beans Convention
The JavaFX Beans Specification
Understanding the Eagerly Instantiated Properties Strategy
Understanding the Lazily Instantiated Properties Strategy
Using Selection Bindings
Adapting JavaBeans Properties to JavaFX Properties
Understanding JavaBeans Properties
Understanding the JavaFX Property Adapters
Summary
Resources
Chapter 5: Building Dynamic UI Layouts in JavaFX
Introducing JavaFX Reversi
Board Layout and Basic Rules
Building a JavaFX Model for Reversi
Dynamic Layout Techniques
Centering Text Using Bind
Centering Revisited Using a StackPane
Aligning to Edges Using StackPanes and TilePanes
Using FlowPane and Boxes for Directional Alignment
Composing a Layout Using BorderPane
Creating Custom Regions
Building a Custom Square Region
Building a Resizable Reversi Piece
Laying Out the Tiles Using a GridPane
Aligning and Stretching with AnchorPane
When to Use Different Layouts
Bringing Reversi to Life
Highlighting Legal Moves
Highlighting the Active Cell
Taking Turns
Declaring the User Interface Using FXML
Additional Game Enhancements
Summary
Resources
Chapter 6: Using the JavaFX UI Controls
Trying Out the JavaFX UI Controls
Leveraging the JavaFX UI Controls
Creating a Menu and Defining Menu Items
Creating a Toolbar
Defining Graphical Buttons
Defining Toggle Buttons
Using Toggle Groups
Inserting a Separator into a Toolbar
Creating a TabPane and Defining Tabs
Creating a TableView
Assigning Items to a Table
Defining TableView Columns
Detecting When a Row Is Selected
Creating an Accordion and Defining a TitledPane
Creating a TreeView
Defining a TreeItem
Detecting When a TreeItem Is Selected
Creating a ListView and Assigning Items to a ListView
Creating a SplitPane
Creating a TreeTableView
Defining a ScrollPane
Using a CheckBox
Defining a RadioButton
Creating a Hyperlink
Defining a ChoiceBox
Using a MenuButton
Creating a ContextMenu
Creating a SplitMenuButton
Defining a TextField
Using a PasswordField
Creating a TextArea
Creating a DatePicker and a ColorPicker
Creating a Slider
Defining a ProgressIndicator
Defining a ScrollBar
Using a ProgressBar
Creating an HTMLEditor
Creating a Popup
Using a WebView
Summary
Resources
Chapter 7: Collections and Concurrency
Understanding Observable Collections and Arrays
Understanding ObservableList
Handling Change Events in ListChangeListener
Understanding ObservableMap
Understanding ObservableSet
Understanding ObservableArrays
Using Factory and Utility Methods from FXCollections
Using the JavaFX Concurrency Framework
Identifying the Threads in a JavaFX Application
Fixing Unresponsive UIs
Understanding the javafx.concurrent Framework
Understanding the Worker Interface
Understanding the Task Abstract Class
Understanding the Service Abstract Class
Understanding the ScheduledService Abstract Class
Mixing JavaFX with Other GUI Toolkits
Embedding JavaFX Scenes in Swing Applications
Embedding JavaFX Scenes in SWT Applications
Embedding Swing Components in JavaFX Applications
Summary
Resources
Chapter 8: Creating Charts in JavaFX
Structure of the JavaFX Chart API
Using the JavaFX PieChart
The Simple Example
Some Modifications
Using the XYChart
Using the ScatterChart
A Simple Implementation
Improving the Simple Implementation
Using the LineChart
Using the BarChart
Using the StackedBarChart
Using the AreaChart
Using the StackedAreaChart
Using the BubbleChart
Summary
Resources
Chapter 9: Using the Media Classes
The Foundation
Supported Media Formats
Working with Audio Clips
Controlling the Playback Parameters of an AudioClip
Constructing the Scene
AudioClip Wrap-Up
Working with Media
Playing Audio
Error Handling
Displaying Metadata
Loading Media
Controlling Playback
Laying Out the Player Controls
Creating Playback Controls
Seeking
Controlling Volume
Repetition
Audio Equalization
MediaPlayer Wrap-Up
Playing Video
Controlling the Size of a MediaView
MediaView and Effects
Using Markers
One Player, Multiple Views
Converting AudioPlayer into a VideoPlayer
Summary
Resources
Chapter 10: JavaFX 3D
Overview
Understanding JavaFX 3D Objects
Understanding the Shape3D Base Class
Creating Predefined 3D Shapes
Creating User-Defined 3D Shapes
Adding Cameras to JavaFX 3D Scenes
Understanding the PerspectiveCamera
Adding Lights to JavaFX Scenes
Understanding the LightBase Class
Understanding the AmbientLight Class
Understanding the PointLight Class
Understanding SubScenes
Specifying the Material of 3D Shapes
Understanding the PhongMaterial Class
Adding Texture to 3D Shapes
Interacting with JavaFX 3D Scenes
Understanding the PickResult Class
Understanding the Canvas and Image Ops APIs
Understanding the Canvas API
Understanding the Image Ops API
Summary
Resources
Chapter 11: Accessing Web Services
Front-End and Back-End Platforms
Merging JavaFX and Java Enterprise Modules in the Same Environment
Using JavaFX to Call Remote (Web) Services
SOAP
REST
Setting Up the Application
Using the StackExchange API
JSON Response Format
XML Response Format
Asynchronous Processing
Converting Web Services Data to TableView
Using External Libraries
DataFX
JAX-RS
Summary
Chapter 12: JavaFX on Embedded and Mobile
OpenJFX, the Origin of the Code
JavaFX on ARM
The Raspberry Pi
JavaFX on the Raspberry Pi
Deploying JavaFX Applications on the Embedded ARM Systems
Using Command-Line Tools
Using NetBeans
JavaFX on Mobile
JavaFX on iOS
JavaFX on Android
JavaFXPorts, Putting It All Together
Summary
Resources
Chapter 13: JavaFX Languages and Markup
A Quick Comparison of Alternative Languages
Vanishing Circles in Java
Vanishing Circles in Alternative JVM Languages
Making Your JavaFX Groovy
Introduction to GroovyFX
Properties in GroovyFX
GroovyFX Binding
GroovyFX API Enhancements
Animation
Tables
Layouts
Scala and JavaFX
Getting Started with ScalaFX
ScalaFX Proxies and Implicit Conversions
JavaFX Properties in Scala
ScalaFX Bind APIs
API Enhancements
Closures
Layout Constraints
Animation
Summary
Resources
Index