JavaFX is Java's modern toolkit for building GUI applications. You build a tree of nodes (controls, layout panes, shapes) inside a Scene, show it in a Stage, handle events with lambdas, and optionally describe the layout in FXML and style it with CSS.
To use it, add the OpenJFX modules to your project (they are not part of the JDK since Java 11), extend Application, and build the UI in start.
Application: the entry point. launch() starts the toolkit and calls start(Stage).Stage: a window. The primary stage is passed to start.Scene: the content of a stage. It holds one root node.VBox, HBox, BorderPane, GridPane, and StackPane size and position their children.Button, Label, TextField, ListView, TableView, and so on.This example collects a name and shows a greeting. It uses a GridPane for layout and an event handler on the button.
setDefaultButton(true) makes Enter trigger the button. The grid places each control by column and row index.
For larger screens, put the layout into an .fxml file and keep logic in a controller. This separates design from behaviour.
Load it with FXMLLoader:
The loader creates the controller and injects the @FXML fields by matching fx:id. If you use the Java module system, open the controller package to javafx.fxml in module-info.java, otherwise injection fails at runtime.
Controls like ListView and TableView observe an ObservableList, so changes to the list update the UI.
Properties work the same way. You can bind a label to a text field with output.textProperty().bind(nameField.textProperty()) so no handler is needed.
JavaFX runs all UI work on the JavaFX Application Thread. Long tasks such as network calls or file loading must run elsewhere, or the window freezes. Use Task and update the UI from its callbacks:
setOnSucceeded runs back on the UI thread. From other code, call Platform.runLater(...) to touch nodes safely.
Attach a stylesheet with scene.getStylesheets().add(...) and style nodes with -fx- properties. For delivery, jpackage creates a native installer (MSI, DMG, DEB, RPM) that bundles a runtime image, so users do not need Java installed.
With Maven and the javafx-maven-plugin, run mvn javafx:run. Without a build tool, put the JavaFX SDK lib folder on the module path and add --add-modules javafx.controls.
Your main class extends Application and the JavaFX modules are not on the module path. Use a separate launcher class that does not extend Application, or pass --module-path and --add-modules.
It is helpful for designing FXML visually. It is a separate download, and you can use it with any IDE.
No. Update nodes on the JavaFX Application Thread with Platform.runLater or Task callbacks.
Build JavaFX GUIs from Stage, Scene, layout panes, and controls. Use FXML and controllers for bigger screens, observable lists and bindings for data, CSS for styling, and Task for background work. Package with jpackage for distribution.