JavaFX is a set of graphics and media packages that enable developers to design, create, test, debug, and deploy rich client applications that operate consistently across diverse platforms.
(Source: Oracle)

As of JDK 7u6 JavaFX is included with the standard JDK and JRE bundles if you have an older Java Installation, either update or navigate here.

Access JavaFX in Eclipse IDE + Java 8
By default, when we access the JavaFX APIs, Eclipse will prompts the Access restriction errors. To solve this, install e(fx)clipse plugin.

JavaFX in Java 8
In Java 8, the JavaFX is not a part of the JavaSE execution environment, but as an external library – lib\ext\jfxrt.jar

JavaFX Hello world example

A simple example where we use GridPane to lay out the 4 Rectangles that draw the background and a BorderPane for the Button and the Label.

JavaFxHelloWorld.java

package com.mkyong.helloworld;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.stage.Stage;

public class JavaFxHelloWorld extends Application {
	
	private int counter = 0;

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

	@SuppressWarnings("static-access")
	public void start(Stage stage) {
		stage.setTitle("Hello World!");

		GridPane grid = new GridPane();
		grid.setHgap(0);
		grid.setVgap(0);

		Rectangle r1 = new Rectangle();
		r1.setFill(Color.DARKKHAKI);
		r1.setHeight(125);
		r1.setWidth(125);

		Rectangle r2 = new Rectangle();
		r2.setFill(Color.rgb(189, 40, 40));
		r2.setHeight(125);
		r2.setWidth(125);

		Rectangle r3 = new Rectangle();
		r3.setFill(Color.hsb(235, 0.52, 0.36));
		r3.setHeight(125);
		r3.setWidth(125);

		Rectangle r4 = new Rectangle();
		r4.setFill(Color.web("b894cc"));
		r4.setHeight(125);
		r4.setWidth(125);

		grid.add(r1, 0, 0);
		grid.add(r2, 0, 1);
		grid.add(r3, 1, 0);
		grid.add(r4, 1, 1);

		Label l = new Label();
		l.setFont(new Font("Calibri", 15));
		l.setTextFill(Color.BLACK);

		Button button = new Button();
		button.setFont(new Font("Calibri", 15));
		button.setText("Say 'Hello World'");

		button.setOnAction(new EventHandler<ActionEvent>() {
			public void handle(ActionEvent event) {
				l.setText("You said Hello to the world: 
					" + ++counter + ((counter == 1) ? " time" : " times"));
			}
		});

		BorderPane bp = new BorderPane();
		bp.setBottom(l);
		bp.setAlignment(l, Pos.CENTER);
		bp.setCenter(button);

		StackPane root = new StackPane();
		root.getChildren().add(grid);
		root.getChildren().add(bp);
		stage.setScene(new Scene(root, 250, 250));
		stage.show();
		
	}
	
}

Output:

javafx-helloworld-1

When “Say ‘Hello World'” button is clicked one time:

javafx-helloworld-2

When “Say ‘Hello World'” button is clicked multiple times:

javafx-helloworld-3

References

  1. Oracle JavaFX Scene Graph
  2. Working with Layouts in JavaFX
  3. Wikipedia JavaFX
  4. Using JavaFX in JRE 8
  5. e(fx)clipse plugin