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




JavaFX Tutorial

Jakob Jenkov
Last update: 2016-05-15

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.

I have been skeptical of JavaFX historically. Why would Java need yet another GUI toolkit? And why was it living side by side with AWT and Swing? Did we really need another GUI toolkit? These, and many other questions haunted me in the early days of JavaFX.

However, things have changed. JavaFX will now replace 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.

All in all, I must say that JavaFX is a welcome step in the right direction for Java on the desktop. There is a community effort to get JavaFX to run on mobile devices too (see futher down this page). Let's hope they succeed with that.

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.

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 Use Cases

I have been asked several times if desktop applications are not dead - if there are really any use cases left for something like JavaFX. It is true, that many applications fit better 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. Here is a list of some of the 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 Gluon project (gluonhq.com) is an open source project which can package your JavaFX applications for Android and iOS.

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:

https://docs.oracle.com/javase/8/javafx/api/toc.htm

Jakob Jenkov




Copyright  Jenkov Aps
Close TOC