Tech and Media Labs
This site uses cookies to improve the user experience.

JavaFX Tutorial

Jakob Jenkov
Last update: 2019-08-03

JavaFX is a GUI toolkit for Java (GUI is short for Graphical User Interface). JavaFX makes it easier to create desktop applications and games in Java. This JavaFX tutorial is a multi-page tutorial explaining the core features of JavaFX. See the menu in the left side of this page to see all the topics covered in this JavaFX tutorial.

Some applications are just easier to create as standalone desktop applications than as web applications. For instance, applications that need to access the local disk of the computer it runs on, or which needs to communicate with many different remote systems, and sometimes using other protocols than HTTP (e.g. IAP or streaming protocols etc.). JavaFX is a good option in these cases. We at Nanosai are actually developing a desktop app using JavaFX for these exact reasons. See JavaFX use cases for more examples.

JavaFX has replaced Swing as the recommended GUI toolkit for Java. Furthermore, JavaFX is more consistent in its design than Swing, and has more features. It is more modern too, enabling you to design GUI using layout files (XML) and style them with CSS, just like we are used to with web applications. JavaFX also integrates 2D + 3D graphics, charts, audio, video, and embedded web applications into one coherent GUI toolkit.

The Gluon company has ported JavaFX so it can run on both Android and iOS. See JavaFX on Mobile Devices for more information.

JavaFX Features

JavaFX comes with a large set of built-in GUI components, like buttons, text fields, tables, trees, menus, charts and much more. That saves you a lot of time when building a desktop applications.

JavaFX components can be styled using CSS, and you can use FXML to compose a GUI instead of doing it in Java code. This makes it easier to quickly put a GUI together, or change the looks or composition without having to mess around in the Java code.

JavaFX contains a set of ready-to-use chart components, so you don't have to code that from scratch every time you need a basic chart.

JavaFX also comes with support for 2D and 3D graphics as well as audio and video support. This is useful if you are developing a game, or similar media applications.

JavaFX even contains a WebView based on the popular WebKit browser, so you can embed web pages or web applications inside JavaFX.

Here is a more complete list of components and features in JavaFX:

Third Party JavaFX Resources

There are a few, cool third party resources available out there. I have listed some of them here:

  • JavaFX Drift - OpenGL etc. support for JavaFX. Seamless integration into the scene graph.
  • ControlsFX - Extra UI controls for JavaFX.

JavaFX Use Cases

I have been asked several times if not desktop applications are dead - if there are really any use cases left for something like JavaFX. It is true, that many applications fit well as web applications, because you access them rarely, and the resources you access are stored on a server anyways. But, there are also several types of applications that are better implemented as desktop applications.

As mentioned in the introduction we at Nanosai are actually developing a desktop application using JavaFX. We do so because that app needs access to the local disk, needs to be able to communicate via other network protocols than HTTP, and needs several other features a standard web browser simply does not provide.

Here is a list of some of general use cases I see for JavaFX:

  • Developer tools
    • IDE
    • Editors
    • File compression / encryption tools
    • Tools scanning the local disk
  • Local system maintenance tools
    • Backup tools
    • Virus scans
  • Utility apps
    • Skype / Messenger / Chat
    • Screen shot tools
    • Photo and video editing
    • Video players
    • Audio editing
    • Audio players
  • Games
  • Data Science Tools

Here are some of the desktop apps I use regularly:

  • IntelliJ IDEA
  • Notepad++
  • SourceTree
  • SnagIt
  • Putty
  • WinSCP
  • Skype
  • PhotoShop
  • Premiere Pro
  • VideoLAN (VLC)
  • EDraw

JavaFX on Mobile Devices

There is a community effort to make JavaFX applications run on mobile devices. The project is called JavaFXPorts and is maintained and supported by Gluon.

JavaFX in Java 8

From Java 8 JavaFX is bundled with the Java platform, so JavaFX is available everywhere Java is.

JavaFX Replaces Swing

JavaFX is intended to replace Swing as the default GUI toolkit in Java. Swing will still be shipped with Java for some time, but you should consider porting your old Java Swing applications to JavaFX some time in the future.

Java Installers

From Java 8 you can also create standalone install packages for Windows, Mac and Linux with Java, which includes the JRE needed to run them. This means that you can distribute JavaFX applications to these platforms even if the platform does not have Java installed already.

Java WebStart

JavaFX applications can also be installed and executed using Java WebStart. To start an application using Java WebStart you need to create a JNLP file (Java Network Launch Protocol) file and put it on a web server, and create a link to it from a web page somewhere. WHen the user clicks the link to the JNLP file the application is downloaded and started.

Once the JavaFX application is installed it can be started again using the same JNLP link. The application is not downloaded the second time. It is executed from the previous installation.

Java WebStart also makes it possible to upgrade the installed JavaFX applications to newer versions. This is a great way to handle upgrades for internal tools in an enterprise. It is almost as seamless as upgrading web applications.

JavaFX in Java 9

JavaFX did not get a lot of new features in Java 9, but it did get 750+ bug fixes, so if you are planning to build a new JavaFX app from scratch, you might want to consider starting with Java 9 !

JavaFX From Java 11

From Java 11, JavaFX has been removed from the Java SDK again. JavaFX has been detached into its own open source project. This means that to download JavaFX from Java 11 / JavaFX 11, you have to go to:

JavaFX JavaDoc

Even though JavaFX is part of Java 8, the JavaFX JavaDoc is not included in the standard Java 8 JavaDoc. You can find the JavaFX JavaDoc here:

Jakob Jenkov

Copyright  Jenkov Aps
Close TOC