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 (on mobile, check the Trail TOC in the bottom navigation bar). There is also an extensive list further down this page.
There are several reasons why JavaFX is a great GUI application platform. First of all, Java is still one of the most popular programming languages in the world, with a large set of standard classes, and a rich set of open source toolkits developed by the Java developer community.
Second, JavaFX can run on all of the following OS'es and devices:
- Android / Chromebook
- Raspberry Pi
This makes JavaFX a versatile cross OS and cross device application toolkit.
Third, JavaFX comes with a rich set of GUI controls, and open source toolkits add even more tools to the total ecosystem.
JavaFX comes with a large set of built-in GUI components, like buttons, text fields, tables, trees, menus, charts and much more. JavaFX can be styled via CSS and / or programmatically. JavaFX comes with a built-in chart library you can use for simple charts. JavaFX has support for 2D and 3D Graphics. JavaFX has a WebView which can display modern web applications.
Here is a more complete list of concepts, components and features in JavaFX:
- Container Controls
- 2D Shapes
- 3D Shapes
- Drag and Drop
- Print API
- High DPI resolution screen support
- Concurrency 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.
- GemsFX - Extra UI controls for JavaFX.
- TilesFX - Extra UI controls for JavaFX.
Resources related to JavaFX:
- Skija - Fast 2D graphics for Java - using hardware accelerated graphics.
Here are some of the publicly available apps made with JavaFX, so you can see for yourself what is possible with JavaFX:
- DBFX - a free database management GUI app (management console).
Why Desktop Applications?
Why are native / local apps preferred for mobile devices - but web apps preferred for desktop computers? Why are native / local apps not preferred for both types of devices?
Native / local apps tend to provide a better user experience than web apps by being more responsive (faster, snappier), having more advanced GUI controls, and by better integrating with the local device. The two biggest problems for traditional desktop apps was low Internet bandwidth and a cumbersome installation process. Both of these problems have pretty much been resolved with high speed Internet connections being quite common, and with app stores for private devices and install-on-demand systems for corporate machines.
In my opinion native / local apps should be preferred for all apps that are being used often, or where the workflow is somewhat complicated. Native / local apps should also be preferred for 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.). See JavaFX use cases for more application examples.
Apps the user use rarely, or which the user is not really motivated to download and install should probably remain as web apps. For instance, an app to login in and administer your insurance contracts is probably fine to implement as as a web app. But a project management tool that your users are using several times per day is probably better off being a desktop app.
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
- 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
- Data Science Tools
Here are some of the desktop apps I use regularly:
- IntelliJ IDEA
- Premiere Pro
- VideoLAN (VLC)
Additionally, several companies that have started with web applications have later added native / local desktop applications. Some of these are:
- YouTube Music
- Microsoft Teams
- Google Drive
JavaFX on Mobile Devices
Gluon offers a set of tools to help you build and package your JavaFX application as native images for mobile (Android and iOS).
JavaFX on Raspberry Pi
It is also possible to run JavaFX on a Raspberry Pi computer. You can read more about how to run JavaFX on Raspberry Pi in the book Getting started with Java on the Raspberry Pi
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:
However, JavaFX keeps evolving and is still very popular among its users.
JavaFX Game Engine
Almas Baim has made the FXGL JavaFX game engine. You can find it at:
JavaFX vs. Swing
You may be aware that Java also has another GUI toolkit called Java Swing (or JFC). In case you wonder what the difference is between the two toolkits, I have listed some of the major differences below:
|Property Bindings||JavaFX properties support binding, meaning you can listen for changes in their values.||Swing properties do not directly support binding.|
|Declarative Layout||JavaFX has support for declarative layout via FXML.||Swing has no built-in support for declarative layout.|
|Styling||JavaFX supports CSS based and code based styling.||Swing only supports code based styling.|
|WebView||JavaFX has a WebView that can render modern web pages.||Swing has no WebView.|
|Graphics||JavaFX uses vector based graphics.||Swing uses pixel based graphics.|
|3D Graphics||JavaFX has built-in support for 3D graphics.||Swing requires the Java 3D API for 3D graphics.|
|Concurrency API||JavaFX has a built-in concurrency API.||Swing has no built-in concurrency API.|
|Age of toolkit||JavaFX is newer.||Swing is older.|
|Included in Java SDK||JavaFX is not included from Java 11 and forward.||Swing is still included, but will probably be removed one day.|
JavaFX Examples on GitHub
I have started adding many of the JavaFX examples from this tutorial to a public GitHub repository for your convenience. The examples are ready-to-run self-contained examples, each with its own class + main() method to run that particular example. Here is the GitHub repository:
Here are the most useful books I have read about JavaFX:
You can find the JavaFX 11 JavaDoc here: