JavaFX is a 3rd Generation Java GUI platform (after AWT, Swing) for the development of Desktop and Rich Internet Applications. As of JDK8, It is a part of Java SE. JavaFX provides resources to build thick client applications that interact with Java SE, ME, and EE. JavaFX supports Windows Vista — Current, Mac OSX — macOS, and various Linux operating systems. There are also ports for various mobile platforms. The current version of Java FX mirrors the JDK numbering as Java FX 9. An overview of the updates to the Java FX Platform of JDK release 9 will be the focus of this article.
Not Caught up to Java 9? Learn more below:
Cool Java 9 Features You Might’ve Missed
While the predominant features of Java SE 9 were the modularity efforts of Project Jigsaw, Java 9 introduced several…
JavaFX happens to be one of my favourite technologies :) I love Desktop Apps. I love Java. And I also like what Danny Coward & the Java Client Group did with JavaFX; It is a refreshing breath in the right direction, learning the lessons from it’s predecessors: AWT & Swing.
Because of the heavy focus on Project Jigsaw (Modularity), JDK 9 included few upgrades to java language features as well as JavaFX APIs. The highlights of Java FX updates in JDK 9 are the Skin/CSS APIs and Jigsaw modularization.
JavaFX is dual licensed under the GPL v2 with Classpath Exception and Oracle Binary Code License for the Java SE Platform with a commitment to go fully open source in the foreseeable future. openJFX is the community effort behind JavaFX.
A Brief Java FX Primer — Hello World
While this article will not examine the JavaFX APIs in depth, if you’ve never seen a JavaFX Application before, below are some screenshots of a Hello World application.
Some screenshots of the execution. The background toggles on the button event’s (clicking off the Hello JavaFX World! button) firing.
Want the source? Grab it here.
Gradle source code repository for the Java FX 9 source code example posted on my personal blog (http://bit.ly/JavaFX9).
So What’s New?
#1 — Modularization (Project Jigsaw)
The first thing to notice is that JavaFX is now broken up into seven modules :
- Base APIs for JavaFX UI Toolkit — javafx.base
- JavaFX APIs for UI Controls — javafx.controls
- JavaFX APIs for FXML — javafx.fxml
- JavaFX APIs for various Graphics Tools— javafx.graphics
- JavaFX APIs for Multimedia — javafx.media
- JavaFX APIs for Swing-JavaFX Interoperability — javafx.swing
- JavaFX APIs for WebView Functionality — javafx.web
The advantages of modularity include improved scalability, ability to test software components independently without breaking code other code or having to recompile an entire system, among others.
The javapackager can now give you an application with only the modules you need. All modular JavaFX applications require the javafx.base & javafx.graphics modules. All modular Java FX UI Applications require the javafx.controls module. Packages may only belong to one module. Modular applications will need to list dependencies in module-info.java.
JEP 253 & JEP 200 were the community efforts towards modularizing the JDK and the JavaFX UI Controls & CSS APIs. They came about by the overall push towards a modular JDK and was incentivized by the advantage of providing public availability for functionality found only in internal APIs.
#2 — Improved Encapsulation
Java FX 9 brings stricter encapsulation on Java FX API internals. This provides some enforcement for better compliance of avoiding the use of the Java FX internal APIs. Only public types of explicitly exported packages are available. While there is a work-around, I won’t mention it, because you should resist the urge to use it ;). Think within the API.
The APIs: com.sun* packages and impl__ methods have been either deprecated, replaced, or made public, now that JDK 9 modularity hides non-public packages. Node builders should be avoided. Class.getResource should be used instead of ClassLoader.getResource(). Classpath relative URL strings should be avoided.
#3 — New API
Commonly, developers were dipping into com.sun.javafx.scene.control.skin to develop Java FX skins. This means that developers were relying on private API. Often enough, the grounds for dipping into JavaFX internal APIs could be argued by the need for functionality. In JDK 9 a new API A new API, javafx.scene.control.skin was released to address this need.
A concomitant consequence of the push towards JDK modularity led to the opportunity to provide public implementation for a lot of very useful private API, hence JEP 253. Beginning in June of 2015, members of the Java Client Group and openJFX began polling the community for the most useful private API. They found the following API to be the most wanting of examination: UI Control Skins, CSS APIs, Toolkit / Platform APIs, Robot, Performance Tracker. All but the Robot and Performance Tracker APIs were addressed in JDK 9.
56 new skin API classes and 11 CSS classes were added in JDK 9.
#4 — Graphical Improvements
In JDK 9, Java FX added High-DPI support and improvements for Linux and Windows.
GTK3 Linux Support —
At present, Ubuntu 16.04 LTS & SWT 4.6 and other platforms have migrated to GTK3. JDK 9 may outlive GTK 2 support. To ensure continuing functionality, JDK 9 added GTK3 support. The community effort behind this was JEP 283.
#5 — Updates to GStreamer, WebKit
The GStreamer platform version was upgraded to the latest version and WebKit was updated with performance enhancements and bug fixes .
#6 — Miscellaneous API Enhancements and Bug Fixes
At least 102 small enhancements in the Tooltip, ComboxBox, Spinner, Node, Font, Collections, & FXPermission APIs were added and more than 756 bug fixes have been made.
Where to learn JavaFX?
Pro JavaFX 9
Pro JavaFX 9 - A Definitive Guide to Building Desktop, Mobile, and Embedded Java Clients | Johan…
Use the JavaFX platform to create rich-client Java applications and discover how you can use this powerful Java-based…
In my opinion, this is the defacto reference text on JavaFX 9. Written by the experts, this is the most expansive text on JavaFX 9 to date and should be familiar reading for every serious JavaFX developer.
JavaFX 9 by Example
JavaFX 9 by Example | Carl Dea | Apress
Create media-rich client applications using JavaFX 9 and the Java 9 platform. Learn to create GUI-based applications…
Another stellar text from Apress press. This is an excellent primer for JavaFX newbies that want to get a solid, rigorous introduction to the platform. Experts can learn from this text as well. I learned about the JavaFX printing API from this text.
 — JavaOne Talk — JavaFX: New & Noteworthy, Kevin Rushforth & Jonathan Giles, Java Client Group, September 2016