Tuesday, December 3, 2013

Run JavaFX on Raspberry Pi

This post try to develope JavaFX Application on Windows 8 and run on Raspberry Pi.

Development host PC: 
OS - Windows 8 Pro
Development Tools: NetBeans IDE 7.4
JDK: jdk 1.7.0_45

Raspberry Pi:
Model B with 8G SD Card
OS: Raspbian wheezy 2013-09-25
Memory Split: 64
Overclock: Medium 900MHz
Run in Text Console mode
java version 1.8.0-ea (build 1.8.0-ea-b117)

- New a JavaFX Application in Netbeans, named "JavaFXHelloPi".

- Modify the Java code to add a button to exit.
package javafxhellopi;

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

public class JavaFXHelloPi 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!");

        Button btnExit = new Button();
        btnExit.setOnAction(new EventHandler<ActionEvent>() {

            public void handle(ActionEvent event) {

        VBox vBox = new VBox();
        vBox.getChildren().addAll(btn, btnExit);

        StackPane root = new StackPane();

        Scene scene = new Scene(root, 300, 250);

        primaryStage.setTitle("Hello World!");

    public static void main(String[] args) {

- It run on Windows 8 like this:

- ftp the created jar, JavaFXHelloPi\dist\JavaFXHelloPi.jar, to Raspberry Pi.

- ssh to Raspberry Pi, run the jar by entering the command:
$ java -jar JavaFXHelloPi.jar

It's just a personal experiment. For official steps, refer: https://wiki.openjdk.java.net/display/OpenJFX/OpenJFX+on+the+Raspberry+Pi

More example of JavaFX on Pi:
JavaFX animation on raspberry Pi

No comments: