JavaFX Tutorial Index

JavaFX Tutorial JavaFX Installation JavaFX Application Structure JavaFX Architecture

JavaFX Applications Charts

JavaFX Bar Chart JavaFX Bubble Chart JavaFX Pie Chart JavaFX Scatter Chart JavaFX Area Chart JavaFX Line Chart

JavaFX 2D Shapes

JavaFX Arc JavaFX Circle JavaFX Ellipse JavaFX Line JavaFX Polygon JavaFX Rectangle JavaFX Color JavaFX Gradient Color

JavaFX 3D Shapes

JavaFX Box JavaFX Cylinder JavaFX Sphere

JavaFX Animations

JavaFX Rotate Transition JavaFX Translate Transition JavaFX Fade Transition JavaFX Fill Transition JavaFX Parallel Transition JavaFX Path Transition JavaFX Pause Transition JavaFX Scale Transition JavaFX Sequential Transition JavaFX Stroke Transition

JavaFX CSS

JavaFX ID Selector JavaFX Inline Styles JavaFX Selectors

JavaFX Effect

JavaFX Blend JavaFX Bloom JavaFX Color Adjust JavaFX Color Input JavaFX Drop Shadow JavaFX Gaussian Blur JavaFX Glow JavaFX Image Input JavaFX Inner Shadow JavaFX Light Distant JavaFX Light Point JavaFX Light Spot JavaFX Lighting JavaFX Motion Blur JavaFX Reflection JavaFX Shadow

JavaFX Layouts

JavaFX Layouts JavaFX BorderPane JavaFX GridPane JavaFX StackPane JavaFX HBox JavaFX TilePane

JavaFX Event Handling

JavaFX Event Handling JavaFX Event Filters JavaFX Convenience Methods

JavaFX Transformation

JavaFX Transformation JavaFX Scaling JavaFX Rotation JavaFX Translation JavaFX Shear

JavaFX UI

JavaFX Menu JavaFX Button JavaFX Button Styling JavaFX CheckBox JavaFX File Chooser JavaFX HyperLink JavaFX Label JavaFX UI Controls JavaFX PasswordField JavaFX ProgressBar JavaFX RadioButton JavaFX ScrollBar JavaFX Slider JavaFX TextField

JavaFX Installation

In order to run JavaFX applications, we need to have eclipse and java installed on our machine.

Prerequisite:

Operating systemAny Operating system (Windows, Linux, Mac)
Memory requirementNo minimum requirement
Disk SpaceNo minimum requirement
JDK versionJDK 1.8 or above

For JavaFX, java is mandatory on the machine.

If you have already installed Java on your machine, you can verify the installation using the following commands:

  • For Windows:
  1. Open Command line.
  2. Type the command, C:\>java -version
  3. Press Enter key. It will display the available version of java.
  • For Linux:
  1. Open Command Terminal.
  2. Type the command, $ java-version.
  3. Press Enter key. It will display the available version of java.

If Java is not configured on your local machine follow the below steps to install java:

1. Install Java SDK from Oracle website, https://www.oracle.com/java/technologies/javase-downloads.html

2. Install JDK from Download files.

3. Follow the instruction given in Documentation to install setup.

4. Set Path for Java compiler

  • For Windows,

Insert ‘;%JAVA_HOME% bin’ at the end of system variable and path

  • For Linux,

Export PATH=$PATH:$JAVA_HOME/bin/

5. Set Java_Home variable to the path in your local machine where java is installed

  • For Windows,

Set Java_Home variable to C:\Program Files\Java\jdk1.8.0_171

  • For Linux,

Export JAVA_HOME=/usr/local/java-current

Installing Eclipse IDE:

1. Visit the link https://www.eclipse.org/downloads/ and download the latest version of the eclipse available on the site.

2. After clicking on the download button, it will download the installer. After successful download click on the exe file, prompt will appear, click on the Run button.

3. It will show various software suits, choose the right one you want to install.

JavaFX Installation

4. We will choose Eclipse IDE for Java Developers. The next screen will appear. Choose the path and click on the Install button.

JavaFX Installation

5. Accept the Eclipse foundation software user agreement by clicking on the Accept button and then in the next window click the Launch button to start Eclipse IDE.

6. Select the workspace directory by clicking on the browse button and once selected click on the Launch button.

JavaFX Installation

Installing JavaFX:

1. Open the Eclipse IDE installed on your machine, click on the Help, then select the Eclipse Marketplace from the drop-down menu.

JavaFX Installation

2. Then in Eclipse Marketplace type javafx in the searchbox and click the enter button.

JavaFX Installation

3. It will show e(fx), install it.

4. Once it is successfully installed you have to restart the eclipse to reflect the changes done.

5. Click on File then select New, Choose Project option, and select JavaFX and under dropdown of it click it on JavaFX project.

JavaFX Installation

6. Click on the Next button and Enter the name of the project let us say “JavaFx" and click on the Finish button.

7. Then you have to download JavaFX from the site https://gluonhq.com/products/javafx/.

8. It will download the zip file, you have to extract it into any folder.

9. Right click on the project and click on Properties, choose the Java Build Path option, and then click on the Libraries tab.

JavaFX Installation

10. Then choose JavaFX SDK, click on the add external JARs from the right menu. Then choose all the .jar files available in the downloaded folder in the lib directory. Click on open then select Apply then Apply and Close.

JavaFX Installation

11. Right click on the project select Run As choose Run Configuration then in arguments tab under VM arguments enter the following text:

        --module-path /path/to/JavaFX/lib  --add-modules=javafx.controls,javafx.fxml

JavaFX Installation

12. Also, you have to uncheck the box saying "Use the – XstartOnFirstThread..”

13. Then at last click Apply and Run.

After successful installation create a new java file in the project by right clicking on the src-> new-> class. Then enter the Java class name and package name if you want.

Java Code:

import javafx.application.Application;  
import javafx.scene.Scene;  
import javafx.scene.control.Button;  
import javafx.stage.Stage;  
import javafx.scene.layout.StackPane;  


public class First extends Application
{  
  
    @Override  
    public void start (Stage primaryStage) throws Exception 
   {  
        Button btn1 = new Button("Welcome");  
        StackPane root = new StackPane();  
        root.getChildren().add(btn1);  
        Scene scene=new Scene (root,600,400);      
        primaryStage.setTitle (" Welcome to JavaFX ");  
        primaryStage.setScene (scene);  
        primaryStage.show();  
    }  
    public static void main (String[] args)  
    {  
        launch(args);  
    }   
}  

In order to run the application, Right click on the java file select Run as, and click on Java Applications. It will show one frame with the title, Welcome to JavaFX, and welcome button added on it.

JavaFX Installation