User Tools

Site Tools


programming:java:javafx

This is an old revision of the document!


Table of Contents

[Java JavaFX GUI Desktop Mobile]

JavaFX

This covers how to download and prepare JavaFX and build a simple Hello World application. The official documentation is available at https://openjfx.io. Also refer to their Getting Started with JavaFX guide.

Setup

You'll need a few things:

  • Java JDK 11+
  • JavaFX Modules
  • Scene Builder (Optional)

Download the JavaFX Modules from https://openjfx.io/. The jmods download is the one with the modules and the SDK contains the .jar files and dynamically linked libraries (e.g. .dylib). The modules are for building runtimes with jlink and the library files are used for compiling. Optionally, also download the Scene Builder from https://gluonhq.com/products/scene-builder/ which is a visual GUI designer to generate .fxml template files.

Hello World

There are examples available at https://github.com/openjfx/samples including this simple Hello World:

HelloFX.java
// Feom https://github.com/openjfx/samples/blob/master/HelloFX/CLI/hellofx/HelloFX.java
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
 
public class HelloFX extends Application {
 
    @Override
    public void start(Stage stage) {
        String javaVersion = System.getProperty("java.version");
        String javafxVersion = System.getProperty("javafx.version");
        Label l = new Label("Hello, JavaFX " + javafxVersion + ", running on Java " + javaVersion + ".");
        Scene scene = new Scene(new StackPane(l), 640, 480);
        stage.setScene(scene);
        stage.show();
    }
 
    public static void main(String[] args) {
        launch();
    }
 
}
programming/java/javafx.1616294233.txt.gz · Last modified: 2021/03/21 02:37 by nanodano