Table of contents
1.
Introduction
2.
Export JavaFX jar files to Java Project
3.
JavaFX from Install New Software
4.
Frequently Asked Questions
4.1.
What is JAR?
4.2.
What are the platforms supported by JavaFX?
4.3.
What is e(fx)clipse?
5.
Conclusion
6.
7.
 
Last Updated: Mar 27, 2024

JavaFX in Eclipse

Author Yashesvinee V
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

JavaFX is an open-source client application platform compatible with any type of system built on Java. They help create and deliver rich desktop and web applications that are capable of running across a wide variety of devices. It is one of the most popular libraries in Java, with numerous tools and frameworks. The Eclipse Integrated Development Environment provided by The Eclipse Foundation is very popular for Java Programming. It provides developer tools and plug-ins for various distributed services used by cloud IDEs and browser interfaces. It contains GUI builders and tools for modelling, reporting, charting, testing, and many more. The Eclipse IDE needs to be configured to run JavaFX applications. Let us see how to do this step by step.

Export JavaFX jar files to Java Project

Step 1: Create a new Java Project by navigating to File > New >Java Project.

Step 2: Right-click on the project in the Package Explorer and click on Properties

Step 3: Navigate to Java Build Path and open the Libraries tab. This will show the list of libraries accessible by the Project.

Step 4: Click on Add Library and choose User Library. Click on Next.

Step 5: Click on New under User Libraries and give an appropriate name. Click on Ok.

Step 6: Click on Add External JAR. In File Explorer, navigate to C:\Program Files \Java\jre1.8.0_333\lib. Locate jfxswt.ja and select it. 

Step 7: Add another external Jar file - jfxrt.jar in C:\Program Files\Java\jre1.8.0_333\ext.

Step 8: Click on Apply and Close.

Step 9: Right-click on the project in the Package Explorer and go to New > Class.  

Step 10: Give a name and click on Finish. In the editor, write a simple program to display Hello World.


A simple program to display Hello World.

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.stage.Stage;

public class FXHelloWorld extends Application 
{

    public static void main(String[] args) 
    {
        launch(args);
    }

    @Override
    public void start(Stage stage) 
   {
        primaryStage.setTitle("JavaFX App");

        Label label = new Label("Hello World, JavaFX !");
        label.setAlignment(Pos.CENTER);
        Scene scene = new Scene(label, 400, 200);

        stage.setScene(scene);
        stage.show();
    }
}
You can also try this code with Online Java Compiler
Run Code

Output:

JavaFX from Install New Software

Step 1: Go to Help > Install New Software.

Step 2: Paste “ https://download.eclipse.org/efxclipse/updates-released/1.2.0/site/ “ in the Work with field and click on Add.

Step 3: Enter e(fx)clipse in the Name field and click on Add.

Step 4: Once all the components are listed, click on Select All and then Next.

Step 5: On the Installation Details page, click on Next and select to accept the terms and conditions. Click on finish.

Step 6: A dialog box to Restart the IDE appears. Click on Restart Now.

Step 7: Create a new project by going to File > New > Project. In the Select a Wizard window, navigate to JavaFX and select JavaFX Project.

Step 8: Give a project name and click on Finish.

Step 9: Create a New Class under the project if not prompted.


Step 10: Enter the same Hello World program in the editor and click on run to see the output.

Frequently Asked Questions

What is JAR?

JAR or Java Archive is a package file format used to combine multiple Java class files and their associated metadata with resources into one file. It contains a compressed version of .class files, audio files, image files, and other directories. It works like a zipped file(.zip) created using the WinZip software.

What are the platforms supported by JavaFX?

JavaFX is available on the Windows, Mac OS X, and Linux platforms. For JavaFX 2.2 and Java SE 7, the JavaFX libraries are installed as part of Java SE. The standalone version of JavaFX 2.2 was available only for Java SE 6 users on Windows until February 2013.

What is e(fx)clipse?

e(fx)clipse is an Eclipse project that provides JavaFX capabilities for the Eclipse IDE. It automatically detects JavaFX inside JDK7 and JDK8, a CSS-Editor for all custom JavaFX attributes, an FXML-Editor and a bootstrap standard for JavaFX projects.

Conclusion

This article has extensively discussed how to run JavaFX applications on the Eclipse IDE. It gives a step-by-step detailed process on how to set up and configure JavaFX onto your Eclipse IDE with ease.

Feeling curious? Coding Ninjas has you covered. Check out our articles on Introduction to JavaFXJavaFX Architecture and JavaFX Application StructureExplore our Library on Coding Ninjas Studio to gain knowledge on Data Structures and Algorithms, Machine Learning, Deep Learning, Cloud Computing and many more! Test your coding skills by solving our test series and participating in the contests hosted on Coding Ninjas Studio! 

Recommended Readings:

Looking for questions from tech giants like Amazon, Microsoft, Uber, etc.? Look at the problems, interview experiences, and interview bundle for placement preparations. Happy Learning!

 

Live masterclass