Installing and Setting Up JavaFX in Eclipse IDE

Download as pdf or txt
Download as pdf or txt
You are on page 1of 22

Vision Paudel

Installing and setting up JavaFX in Eclipse IDE 1

Installing and setting up JavaFX in Eclipse IDE


There are two ways of doing this. You only need to install and set up using one of the ways.
The Ways:
In the first way, you download and install Open JavaFX and set it up in Eclipse. Then, you need to provide VM
argument. Since VM argument(s) are not exported to jar files, you will not be able to export code to a working
runnable jar file and will need shell scripts to properly run the jar files. You also need to import the library for
every project you create.
In the second way, you download and install JDK 8u291 and set it up in Eclipse. Then you use the JavaFX
provided in that SDK. This way, you will be able to export code to a working runnable jar file. If you have Macs,
this is the preferred way to do it. First way has not work for some students with Macs.
Follow the steps below to download, install and set up based on your preferred method:
Way 1:
For Way 2: click here
1. Go to openjfx.io and click on Download
Vision Paudel
Installing and setting up JavaFX in Eclipse IDE 2

2. Scroll down to Latest Release, select the appropriate download based on your OS.

For 64-bit
Windows

For 32-bit
Windows

For macOS

3. Once it finishes downloading, open the zipped folder and extract it to the location of your choice. For
demonstration, I have unzipped it to C:\OpenJFX\openjfx-16_windows-x64_bin-sdk\
Vision Paudel
Installing and setting up JavaFX in Eclipse IDE 3

4. In Eclipse, right click your project, go to Build Path > Configure Build Path…
Vision Paudel
Installing and setting up JavaFX in Eclipse IDE 4

5. Click on Libraries. Then click on Modulepath and Add Library…

6. Click on User Library and click Next >


Vision Paudel
Installing and setting up JavaFX in Eclipse IDE 5

7. Click on User Libraries…

8. Click on New… Select System library. Give it a name such as JavaFX


Vision Paudel
Installing and setting up JavaFX in Eclipse IDE 6

9. Click on External JARs…

10. Go to the folder where you extracted the openjfx. Then, go into the lib folder. Select all the
executable jar files and click Open
Vision Paudel
Installing and setting up JavaFX in Eclipse IDE 7

11. Click on Apply and Close, then click on Finish.


Vision Paudel
Installing and setting up JavaFX in Eclipse IDE 8

12. Click on Apply and Close.

13. Create new Class, call it MyFirstGUIProgram, then click Finish.


Vision Paudel
Installing and setting up JavaFX in Eclipse IDE 9

14. Delete the template code. Copy the code below and paste it into your MyFirstGUIProgram.java file.
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class MyFirstGUIProgram extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
StackPane pane = new StackPane();
pane.getChildren().add(new Label("Hello World!"));
Scene scene = new Scene(pane, 200, 50);
primaryStage.setTitle("First JavaFX Demo!");
primaryStage.setScene(scene);
primaryStage.show();
}
}

15. Click on Run Configuraions…


Vision Paudel
Installing and setting up JavaFX in Eclipse IDE 10

16. Click on (x)= Arguments. Then click on VM arguments.


Put argument --module-path “path to lib folder” --add-modules=javafx.controls
Replace “path to lib folder” with actual path to lib folder from before. Click Run.

17. The program should successfully run.

You are done


Vision Paudel
Installing and setting up JavaFX in Eclipse IDE 11

Way 2 :
For Way 1, Click Here
1. Go to
https://drive.google.com/drive/folders/1WQnDgH3IMLGEYMqiNGlBWIY-qE6CZSr6?usp=sharing

For macOS For 64-bit


Windows

2. Download appropriate JDK based on your OS. Run it, click Yes when prompted for Admin Access.
Click Next
Vision Paudel
Installing and setting up JavaFX in Eclipse IDE 12

3. Click Next >

4. Click Next
Vision Paudel
Installing and setting up JavaFX in Eclipse IDE 13

5. Click Close
Vision Paudel
Installing and setting up JavaFX in Eclipse IDE 14

6. In Eclipse, Create a Java Project. Then Click Use default JRE ‘jre’ and workspace compiler preferences.
Then click on Configure JREs…
Vision Paudel
Installing and setting up JavaFX in Eclipse IDE 15

7. Click on Add…

8. Click on Standard VM. Click Next >


Vision Paudel
Installing and setting up JavaFX in Eclipse IDE 16

9. Click on Directory…

10. Go to your java installation folder. If you didn’t change it, it would be C:\Program
Files\Java\jre1.8.0_291\ Then Select Folder
Vision Paudel
Installing and setting up JavaFX in Eclipse IDE 17

11. Click Finish

12. Deselect the old jre and click on the new jre (jre1.8.0.291) making it default. Click Apply and Close
Vision Paudel
Installing and setting up JavaFX in Eclipse IDE 18

13. The compiler compliance level should be changed. Click on Configure…


Vision Paudel
Installing and setting up JavaFX in Eclipse IDE 19

14. Select 1.8. Then, Click Apply and Close.


Vision Paudel
Installing and setting up JavaFX in Eclipse IDE 20

15. Click Yes on Rebuild to apply these changes?

16. Give your project the name MyFirstGUIProgram. Click Finish.


Vision Paudel
Installing and setting up JavaFX in Eclipse IDE 21

17. Create new class. Call it MyFirstGUIProgram. Click Finish.


Vision Paudel
Installing and setting up JavaFX in Eclipse IDE 22

18. Delete the template code. Copy the code below and paste it into your MyFirstGUIProgram.java file.
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class MyFirstGUIProgram extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
StackPane pane = new StackPane();
pane.getChildren().add(new Label("Hello World!"));
Scene scene = new Scene(pane, 200, 50);
primaryStage.setTitle("First JavaFX Demo!");
primaryStage.setScene(scene);
primaryStage.show();
}
}

19. Click Run


The program should successfully run.

You are done

You might also like