JavaFX step by step Part 1 — Getting Started with JavaFX

Chamod Shehanka Perera
The Java Report
Published in
4 min readNov 25, 2018
JavaFX with Chamod Shehanka

Hey, Welcome to JavaFX tutorial series.

What’s JavaFX ?

JavaFX is a software platform for creating and delivering desktop applications, as well as rich Internet applications that can run across a wide variety of devices. JavaFX is intended to replace Swing as the standard GUI library for Java SE, but both will be included for the foreseeable future.

Features of JavaFX

  • FXML — It’s an an XML-based user interface markup language created by Oracle Corporation for defining the user interface of a JavaFX application.
  • Scene Builder — Scene Builder is a visual layout tool that lets users quickly design JavaFX application user interfaces, without coding. Users can drag and drop UI components.
  • Swing Compatibility — In a JavaFX apps, you can embed Swing content using the Swing Node class. And, you can update the existing Swing applications with JavaFX features like embedded web content and rich graphics media.
  • CSS Styling — You can style your applications by using CSS classes.
  • Rich sets of API’s — JavaFX library provides a rich set of API’s to develop GUI applications, 2D and 3D graphics, etc. This set of API’s also includes capabilities of Java platform. Therefore, using this API, you can access the features of Java languages such as Generics, Annotations, Multithreading, and Lambda Expressions. The traditional Java Collections library was enhanced and concepts like observable lists and maps were included in it. Using these, the users can observe the changes in the data models.

You can see a preview of the JavaFX Architecture in the following diagram :

JavaFX Architecture

In that tutorial, you’re going to learn how to create your first JavaFX 11 Application with Intellij IDEA. So, You need to have the JDK 11 and Intellij IDEA installed on your computer before to start this tutorial.

After that open Intellij IDEA

  1. If no project is currently open in IntelliJ IDEA, click Create New Project on the Welcome screen. Otherwise, select File | New | Project. As a result, the New Project wizard opens.
  2. In the left-hand pane, select JavaFX. (We want a Java-enabled project to be created, or, to be more exact, a project with a Java module.)
JavaFX New Project

3. Then click Next Button and put a project name and specify project location whatever you want to save it.
Click Finish.

Wait while IntelliJ IDEA is creating the project. When this process is complete, the structure of your new project is shown in the Project tool window.

Explore the project

Let’s take a quick look at what we’ve got in the project.

Project Structure

The folder src is for your source code. In this folder, there is already a package called sample containing three files:

  • Main.java This is the main application class for starting the sample application.
  • sample.fxml This is the FXML file for defining the user interface.
  • Controller.java. This is the controller class intended to handle user interactions with the UI.
JavaFX Run Configuration

In addition to the sample application source code, there is a run/debug configuration for running or debugging the application. The run configuration has the same name as the main application class (Main) and is shown in the run configuration selector on the toolbar.

Run the sample application

To make sure that everything is fine with the project, let’s run the sample application straight away:

  • Click ▶ on the toolbar.

IntelliJ IDEA compiles the source code and then starts the application. The application window appears which, at the moment, is empty.

JavaFX Sample Application

So, this is all for the Getting started with JavaFX. I hope now you have an idea about JavaFX and it’s features. Don’t forget to comment with your ideas. See you soon…

Follow me on

--

--

Chamod Shehanka Perera
The Java Report

Software Engineer | GitHub Field Expert | Golang Sri Lanka Lead | GDG Organizer | KCD Sri Lanka Organizer| Beginner Surfer