JavaFX Tutorial



This article is a tutorial on the JavaFX GUI library.

What is JavaFX?

JavaFX is a GUI toolkit for creating and delivering desktop applications, as well as rich Internet applications. It comes with a rich set of GUI controls, and open source tool-kits that add even more tools to the total ecosystem.

JavaFX was introduced in 2008 as a successor to the GUI Library Swing. Swing is still the more developed and mature (older) GUI library, but JavaFX is newer and is even compatible with Swing in many ways. Furthermore, JavaFX works better with Mobile Platforms than Swing and across all operating systems such as MacOS, Linux, Android, iOS and Windows.

Why use JavaFX?

Out of all the GUI libraries and programming libraries, why should one pick JavaFX over the others? As mentioned earlier, JavaFX is cross platform and works well on mobile devices. Other languages like Python have separate libraries Mobile and Desktop based applications. JavaFX is all those libraries and functionality rolled into one.

Finally, JavaFX is newer than either Swing or AWT and is the latest GUI flagship of Java. Most GUI applications being developed nowadays are using JavaFX. This ensures that JavaFX will have a long life, whereas AWT has already become a Legacy and Swing is mostly being used in previously existing applications.


JavaFX Tutorial

JavaFX is a massive library with dozens of different widgets, layouts and other GUI components. Our JavaFX Tutorial covers all of these components and features. A list of them divided by category can be found below.

If you haven’t yet setup JavaFX, read our Installation tutorial here.

Widgets

Widgets are the small GUI components in JavaFX that add new and rich functionality to the program. Below is a list of them along with a short description.

  • Stage – Creates the JavaFX GUI Window.
  • Scene – Used to manage the area within the JavaFX Window.
  • Label – Used to display simple lines of text.
  • Button – Clicking on a button will trigger an “event” which causes something to happen.
  • TextField – Used to take input from the user in a single line.
  • RadioButton – Presents the user with some options represented by RadioButtons. Only one option may be selected.
  • CheckBox – Presents the user with some options represented by Check Boxes. Multiple options may be selected.
  • ComboBox – Presents the user with a drop down list from which one option may be selected.
  • TextArea – Used to take multi-line input from the user.
  • MenuButton – Presents the user with a list of options in the form of a button and drop down list.
  • ImageView – Used to display images in the JavaFX GUI window.
  • PasswordField – A special entry field to take passwords as input.
  • FileChooser – Used to select a file from the local computer.
  • Input Dialogs – Presents a dialog to the user, returning the user’s input.
  • Alert Dialogs – Presents the user with an “Alert” in the form of a dialog.

Layouts

Layout managers determine the position and setting of the widgets in the GUI window. Each Layout component in the list below has it’s own unique way of positioning components in the layout.

Other reading material:

An expanding list of extra JavaFX related articles meant to further improve one’s skills and understanding of the Java GUI library.


This marks the end of the JavaFX Tutorial. Any suggestions or contributions for CodersLegacy are more than welcome. Questions regarding the article content can be asked in the comments section below.

Leave a Reply

Your email address will not be published. Required fields are marked *