JavaFX: Creating the first application

This entry is part 2 of 55 in the series JavaFX

If you have been using the full bundle Netbeans package, the only other kit that you need to have in your PC is the Java JDK 8. Java JDK 8 is the latest Java Development kit.

You can also check if you can create a JavaFX application by clicking on the menu File -> New Project.


If JavaFX is listed as one of the categories, you are good to go.  Else you might have to download the JDK again.

Now we will create the default JavaFX program that comes with Netbeans.

1. From the menu, click on File -> New Project.


2. Select JavaFX, JavaFX Application.  Click on Next.


3. We can use the default settings in the above screenshot and proceed to click on Finish to let the Netbeans create for us the first application.

4.  Do take note of that the application class will be called JavaFXApplication5.

5. Once you have clicked Finish, a basic button program would have been created for us.

Netbeans Default Button Application
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
package javafxapplication5;

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

 * @author daryl
public class JavaFXApplication5 extends Application {
    public void start(Stage primaryStage) {
        Button btn = new Button();
        btn.setText("Say 'Hello World'");
        btn.setOnAction(new EventHandler<ActionEvent>() {
            public void handle(ActionEvent event) {
                System.out.println("Hello World!");
        StackPane root = new StackPane();
        Scene scene = new Scene(root, 300, 250);
        primaryStage.setTitle("Hello World!");

     * @param args the command line arguments
    public static void main(String[] args) {

6.  Notice that the class name is called JavaFXApplication5.  This is actually an extension of the JavaFX Application class.

7.  If you run the program, we will have a window as shown below.


Series Navigation<< JavaFX: Introduction
JavaFX: Structure of a JavaFX application >>