JavaFX - Environment



From Java8 onwards, the JDK (Java Development Kit) includes JavaFX library in it. Therefore, to run JavaFX applications, you simply need to install Java8 or later version in your system.

The latest version of JDK, as of today, is 20.0.1. So, this tutorial will work with JavaFX versions supported by JDK20.

In addition to it, IDE’s like Eclipse and NetBeans provide support for JavaFX. This chapter teaches you how to set the environment to run JavaFX Applications locally.

Installing Java20

First of all, you will have to verify whether there is Java Installed in your system or not by opening the command prompt and typing the command “Java” in it.

If you haven’t installed Java in your system, the command prompt displays the message shown in the following screenshot.

Installing Java

You can install Java by following the steps given below.

Step 1 − Visit the JavaSE Downloads Page, click on the JDK Download button as highlighted in the following screenshot

Java SE Downloads

Step 2 − On clicking the highlighted link, the Java20 Development Kit suitable for Windows 64-bit Operating System will be downloaded onto your system.

Step 3 − Run the downloaded binary executable file to start the installation of JDK20.

Java SE Development Kit 8 Next

Step 4 − Change the installation directory if needed, else keep the default ones and proceed further.

Destination Folder

Step 5 − On selecting the destination folder and clicking Next, the JavaFX installation process starts displaying the progress bar.

Extracting Installer

Step 6 − Finish the installation process by clicking the Close button as shown in the following screenshot.

Java SE Installed

Step 7 − To verify if the installation is done properly, go to the command prompt and execute the 'java -version' command as shown below −

Java Version

Setting up the Path for Windows

After installing Java, you need to set the path variables. Assume that you have installed Java in C:\Program Files\java\jdk-20 directory.

Now you can follow the steps that are given below −

  • Right-click on 'My Computer/This PC' and select 'Properties'.

  • Then, select 'Advanced System Settings'.

  • Click on the 'Environment Variables' button under the 'Advanced' tab.

  • Now, alter the 'Path' variable so that it also contains the path to the Java executable. For Example, if the path is currently set to 'C:\WINDOWS\SYSTEM32', then change your path to read 'C:\WINDOWS\SYSTEM32; C:\Program Files\java\jdk-20\bin'.

Edit Environment Variable

Also, create a new system variable by clicking 'New' under System variables as shown below.

Create New System Variable

Name the new variable as "JAVA_HOME" and point it to the JDK installation directory.

JAVA_HOME System Variable

Installing JavaFX SDK

Now, you have to install the JavaFX SDK to access the command-line tools and technologies to develop application content.

In order to use the JavaFX SDK to run a program, follow the steps given below −

Step 1 − Download an appropriate JavaFX runtime for your operating system (here, we are downloading JavaFX 20) from the JavaFX - Gluon page.

JavaFX SDK

Step 2 − A .zip folder will be downloaded containing tools required to develop content for applications. Unzip this folder to any desired location (say, "C:/JavaFX").

Step 3 − Now, right-click on 'My Computer/This PC' and select 'Properties'. Then, select 'Advanced System Settings'. Click on the 'Environment Variables' button under the 'Advanced' tab. Create a new environment variable and name it "PATH_TO_FX" pointing to the lib directory of the JavaFX runtime.

JavaFX PATH_TO_FX

This will now allow you to compile and run JavaFX applications from the command line using the downloaded JavaFX runtime.

Advertisements