{{tag>Java JavaFX GUI Desktop Mobile}} ====== JavaFX ====== JavaFX is a GUI library for Java that can be used on desktop. The official documentation is available at [[https://openjfx.io]]. Also refer to their [[https://openjfx.io/openjfx-docs/|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 a few helpful resources to get started: * Examples on GitHub [[https://github.com/openjfx/samples]] * Running from the CLI [[https://openjfx.io/openjfx-docs/#install-javafx]] * Run HelloWorld using Maven [[https://openjfx.io/openjfx-docs/#maven]] Here is a simple Hello World example: // 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(); } }