First Java FX Application

Prerequisites for starting to develop JavaFX Application:

– Make sure that java 1.7 is specified as project SDK in your IDE.

– If you are using java 1.6, add jfxrt.jar as a dependency to the project.

Mandatory steps involved in creating an application:

– Create a Java class and extend it with Application abstract class.

– Implement start method which gets invoked when the application is started.

– Implement a main method and invoke launch method

– Provide the implementation inside start method


– Create the nodes which need to displayed on user interface

– Create a layout manager such as Border Pane

– Add the nodes to the layout manager

– Create a scene and specify layout manager as the root of scene graph

– Set the scene on primary stage provided by application

– Show the stage such that the stage is visible with computed preferred size


public class JavaFXApplication extends Application
   public static final String TITLE = "Java FX Application";
   private Button closeButton = new Button("Close");

   public void start(Stage stage) throws Exception

      closeButton.setPrefSize(50, 25);

      BorderPane root = new BorderPane();

      stage.setScene(new Scene(root, 400, 300));;

    private void initializeStage(Stage stage)

    public static void main(String[] args)


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s