What Is JavaFX?

Oracle Endeca Information Discovery OverviewJavaFX is an open source Java-based framework for developing rich client applications. It is comparable to other frameworks on the market such as Adobe Flex and Microsoft Silverlight. JavaFX is also seen as the successor of Swing in the arena of graphical user interface (GUI) development technology in Java platform. The JavaFX library is available as a public Java application programming interface (API). JavaFX contains several features that make it a preferred choice for developing rich client applications:

  • JavaFX is written in Java, which enables you to take advantage of all Java features such as multithreading, generics, and lambda expressions. You can use any Java editor of your choice, such as NetBeans, to author, compile, run, debug, and package your JavaFX application.
  • JavaFX supports data binding through its libraries.
  • JavaFX code can be written using any Java virtual machine (JVM)-supported scripting languages such as Visage, Groovy, and Scala.
  • JavaFX offers two ways to build a user interface (UI): using Java code and using FXML. FXML is an XML-based scriptable markup language to define a UI declaratively. Oracle provides a tool called Scene Builder, which is a visual editor for FXML.
  • JavaFX provides a rich set of multimedia support such as playing back audios and videos. It takes advantage of available codecs on the platform.
  • JavaFX lets you embed web content in the application.
  • JavaFX provides out-of-the-box support for applying effects and animations, which are important for developing gaming applications. You can achieve sophisticated animations by writing a few lines of code.

Behind the JavaFX API lies a number of components to take advantage of the Java native libraries and the available hardware and software. JavaFX components are shown in Figure 1.

Components of the JavaFX platform 

Figure 1. Components of the JavaFX platform

The GUI in JavaFX is constructed as a scene graph. A scene graph is a collection of visual elements, called nodes, arranged in a hierarchical fashion. A scene graph is built using the public JavaFX API. Nodes in a scene graph can handle user inputs and user gestures. They can have effects, transformations, and states. Types of nodes in a scene graph include simple UI controls such as buttons, text fields, two-dimensional (2D) and three-dimensional (3D) shapes, images, media (audio and video), web content, and charts.

Prism is a hardware-accelerated graphics pipeline used for rendering the scene graph. If hardware-accelerated rendering is not available on the platform, Java 2D is used as the fallback rendering mechanism. For example, before using Java 2D for rending, it will try using DirectX on Windows and OpenGL on Mac Linux and embedded platforms.

The Glass Windowing Toolkit provides graphics and windowing services such as windows and the timer using the native operating system. The toolkit is also responsible for managing event queues. In JavaFX, event queues are managed by a single, operating system–level thread called JavaFX Application Thread. All user input events are dispatched on the JavaFX Application Thread. JavaFX requires that a live scene graph must be modified only on the JavaFX Application Thread.

Prism uses a separate thread, other than the JavaFX Application Thread, for the rendering process. It accelerates the process by rendering a frame while the next frame is being processed. When a scene graph is modified, for example, by entering some text in the text field, Prism needs to re-render the scene graph. Synchronizing the scene graph with Prism is accomplished using an event called a pulse event. A pulse event is queued on the JavaFX Application Thread when the scene graph is modified and it needs to be re-rendered. A pulse event is an indication that the scene graph is not in sync with the rendering layer in Prism, and the latest frame at the Prism level should be rendered. Pulse events are throttled at 60 frames per second maximum.

The media engine is responsible for providing media support in JavaFX, for example, playing back audios and videos. It takes advantage of the available codecs on the platform. The media engine uses a separate thread to process media frames and uses the JavaFX Application Thread to synchronize the frames with the scene graph. The media engine is based on GStreamer, which is an open source multimedia framework.

The web engine is responsible for processing web content (HTML) embedded in a scene graph. Prism is responsible for rendering the web contents. The web engine is based on WebKit, which is an open source web browser engine. HTML5, Cascading Style Sheets (CSS), JavaScript, and Document Object Model (DOM) are supported.

Quantum toolkit is an abstraction over the low-level components of Prism, Glass, Media Engine, and Web Engine. It also facilitates coordination between low-level components.



History of JavaFX

JavaFX was originally developed by Chris Oliver at SeeBeyond and it was called F3 (Form Follows Function). F3 was a Java scripting language for easily developing GUI applications. It offered declarative syntax, static typing, type inference, data binding, animation, 2D graphics, and Swing components. SeeBeyond was bought by Sun Microsystems and F3 was renamed JavaFX in 2007. Oracle acquired Sun Microsystems in 2010. Oracle then open sourced JavaFX in 2013.

The first version of JavaFX was released in the fourth quarter of 2008. The current release for JavaFX is version 8.0. The version number jumped from 2.2 to 8.0. From Java 8, the version numbers of Java SE and JavaFX will be the same. The major versions for Java SE and JavaFX will be released at the same time as well. Table 1-1 contains a list of releases of JavaFX. Starting with the release of Java SE 8, JavaFX is part of the Java SE runtime library. From Java 8, you do not need any extra set up to compile and run your JavaFX programs.

Table 1. JavaFX Releases

Release Date



Q4, 2008

JavaFX 1.0

It was the initial release of JavaFX. It used a declaration language called JavaFX Script to write the JavaFX code.

Q1, 2009

JavaFX 1.1

Support for JavaFX Mobile was introduced.

Q2, 2009

JavaFX 1.2


Q2, 2010

JavaFX 1.3


Q3, 2010

JavaFX 1.3.1


Q4, 2011

JavaFX 2.0

Support for JavaFX script was dropped. It used the Java language to write the JavaFX code. Support for JavaFX Mobile was dropped.

Q2, 2012

JavaFX 2.1

Support for Mac OS for desktop only was introduced.

Q3, 2012

JavaFX 2.2


Q1, 2014

JavaFX 8.0

JavaFX version jumped from 2.2 to 8.0. JavaFX and Java SE versions will match from Java 8.


System Requirements

You need to have the following software installed on your computer:

  • Java Development Kit 8
  • NetBeans IDE 8.0 or later

It is not necessary to have the NetBeans IDE to compile and run the programs in my blog. However, the NetBeans IDE has special features for creating, running, and packaging JavaFX applications to make developers’ lives easier. You can use any other IDE, for example, Eclipse, JDeveloper, or IntelliJ IDEA.


JavaFX Runtime Library

All JavaFX classes are packaged in a Java Archive (JAR) file named jfxrt.jar. The JAR file is located in the jre\lib\ext directory under the Java home directory.

If you compile and run JavaFX programs on the command line, you do not need to worry about setting the JavaFX runtime JAR file in the CLASSPATH. Java 8 compiler (the javac command) and launcher (the java command) automatically include the JavaFX runtime JAR file in the CLASSPATH.

The NetBeans IDE automatically includes the JavaFX runtime JAR file in the CLASSPATH when you create a Java or JavaFX project. If you are using an IDE other than NetBeans, you may need to include jfxrt.jar in the IDE CLASSPATH to compile and run a JavaFX application from inside the IDE.


JavaFX Source Code

Experienced developers sometimes prefer to look at the source code of the JavaFX library to learn how things are implemented behind the scenes. Oracle provides the JavaFX source code. The Java 8 installation copies the source in the Java home directory. The file name is javafx-src.zip. Unzip the file to a directory and use your favorite Java editor to open the source code.



Вас заинтересует / Intresting for you:

Your First JavaFX Application ...
Your First JavaFX Application ... 1437 views Taniani Thu, 05 Jul 2018, 18:51:01
AWS SDK – Java
AWS SDK – Java 1056 views amiran Thu, 31 May 2018, 13:42:30
Java and Object-Oriented Progr...
Java and Object-Oriented Progr... 1125 views Doctor Thu, 02 Aug 2018, 10:33:18
Evolution of Java Deployment P...
Evolution of Java Deployment P... 907 views sergejh Fri, 26 Oct 2018, 05:09:07