How to add JavaFX library to IntelliJ IDEA and Java 11-14? – you won’t believe how easy it is!

How to add JavaFX library to IntelliJ IDEA and Java 11-14? - you won't believe how easy it is!
Share this post and Earn Free Points!

In this tutorial" I will show you how to add JavaFX library to IntelliJ IDEA". With Java 11, JavaFX" libraries (javafx with intellij idea") were excluded from the JDK library, so to use it you need to download and manually attach the missing libraries to the project.

What is JavaFX?

JavaFX" is a platform for creating and deploying desktop applications and rich Internet applications (RIAs). It is a part of the Java" Runtime Environment (JRE) and can be used with any Java" application. JavaFX" is the next step in the evolution of Java" as a rich client platform. It is designed to provide a lightweight, hardware-accelerated Java" UI platform for enterprise business applications.

JavaFX" has been designed to address the needs of today’s business applications. These applications need to be highly engaging with rich media and content, and they need to be able to run on a variety of devices. JavaFX" provides a powerful Java-based UI platform capable of handling large-scale data-driven business applications.

JavaFX" is a complete platform that includes a new language, a new set of libraries, and new tooling. It is an open source project led by Oracle". The goal of JavaFX" is to make it easier for developers to create and deploy rich Internet applications (RI

JavaFX download -> How to add JavaFX library to IntelliJ IDEA

To download the package, go to https://gluonhq.com/products/javafx/ and select the appropriate version for us. In my case it will be “JavaFX Linux" SDK”.

The downloaded package should be unpacked. We will be adding these libraries to the project in the next steps.

How to add JavaFX library to IntelliJ IDEA and Java 11-14? - you won't believe how easy it is!
How to add JavaFX library to IntelliJ IDEA and Java 11-14? - you won't believe how easy it is! 6

Setup JDK -> Java 11 and Java 14

In IntelliJ go to File -> Project Structure -> Project, and then set the appropriate JDK version.

How to add JavaFX library to IntelliJ IDEA and Java 11-14? - you won't believe how easy it is!
How to add JavaFX library to IntelliJ IDEA and Java 11-14? - you won't believe how easy it is! 7

In the Modules tab, we also set the correct JDK.

How to add JavaFX library to IntelliJ IDEA and Java 11-14? - you won't believe how easy it is!
How to add JavaFX library to IntelliJ IDEA and Java 11-14? - you won't believe how easy it is! 8

How do I add JavaFX to IntelliJ to an existing project?

Then go to File -> Project Structure -> Libraries and add New Project Library by clicking the plus button +. Select the lib folder in the directory where we previously unpacked the JavaFX SDK library.

(We can also define this library as Global Libraries, and then only import to individual projects / modules).

How to add JavaFX library to IntelliJ IDEA and Java 11-14? - you won't believe how easy it is!
How to add JavaFX library to IntelliJ IDEA and Java 11-14? - you won't believe how easy it is! 9

Launching the application

If you get an error when starting the application:

Error: JavaFX" runtime components are missing, and are required to run this application

then you need to add the JavaFX".graphics module in the VM options (remember to change the path).

Linux

--module-path /home/pawel/Desktop/javafx-sdk-11.0.2/lib --add-modules javafx.controls,javafx.fxml

Windows

--module-path "C:\javafx-sdk-11.0.2/lib" --add-modules javafx.controls,javafx.fxml

It’s all! Run the app and see it works! 🙂

Add JavaFx To pom.xml

To add the JavaFX library to IntelliJ IDEA", follow these steps:

  1. Open" IntelliJ IDEA and create a new project or Open" an existing project.
  2. Click on the File menu and select Project Structure.
  3. In the Project Structure window, select the Libraries tab.
  4. Click the + button and select Java.
  5. Navigate to the folder where you have installed the JavaFX" library and select the jfxrt.jar file.
  6. Click OK to add the library to your project.

Alternatively, you can also add the JavaFX library to your project using the following Maven" dependency:

<dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-controls</artifactId>
    <version>11</version>
</dependency>

To do this, you need to have the Maven plugin installed in your IntelliJ IDEA. If you don’t have the Maven plugin installed, follow these steps:

  1. Click on the File menu and select Settings.
  2. In the Settings window, go to Plugins.
  3. Click on the Marketplace tab and search for Maven.
  4. Click on the Install button to install the plugin.

Once the Maven plugin is installed, you can add the JavaFX" library to your project by following these steps:

  1. Open" the pom.xml file of your project.
  2. Add the following dependency to the dependencies section:
<dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-controls</artifactId>
    <version>11</version>
</dependency>
  1. Click on the Maven Projects button in the toolbar and select Reimport All Maven Projects. This will download the JavaFX" library and add it to your project.

I hope this helps! Let me know if you have any questions.

Could You Please Share This Post? 
I appreciate It And Thank YOU! :)
Have A Nice Day!

How useful was this post?

Click on a star to rate it!

Average rating 4.9 / 5. Vote count: 447

No votes so far! Be the first to rate this post.

As you found this post useful...

Follow us on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?