Skip to content
CalliCoder

4 tutorials

JavaFX tutorials

Every JavaFX guide on the site, newest first. Each one is built around code you can run.

JavaFX is the current toolkit for desktop Java applications, and it works quite differently from Swing: layout is declarative, styling is CSS, and the scene graph is a retained-mode tree rather than something you paint yourself.

These guides cover the pieces of an application: the stage and scene, the layout panes and when each is the right choice, the standard controls, event handling and property binding, and styling with CSS including where JavaFX diverges from what a web stylesheet would do.

Examples are runnable applications with their build configuration shown, since JavaFX moved out of the JDK the module and dependency setup is the step most likely to stop you before any code runs.

Layout gets the most attention, because choosing the wrong pane is the source of most JavaFX frustration. VBox and HBox are simple and inflexible, BorderPane suits application shells, GridPane handles forms, and AnchorPane gives absolute positioning that stops resizing correctly. Picking well at the start avoids fighting the layout later.

Properties and binding are treated as core rather than advanced. A JavaFX property is observable, bindings keep derived values current without event plumbing, and once that clicks a great deal of listener code becomes unnecessary.

The guides assume a desktop target. JavaFX can be packaged for distribution with jlink and jpackage, and the build configuration shown accounts for that even in the smaller examples, since retrofitting it later is more work than including it from the start.

Two rules govern most JavaFX problems. The scene graph may only be touched from the JavaFX Application Thread, so any work that takes measurable time belongs on a background thread and the result is handed back for display; the Task and Service classes exist for exactly this and carry progress and failure states with them. The second is packaging: JavaFX has shipped separately from the JDK since Java 11, so it is a dependency your build declares rather than something present on every machine. The guides state which JDK and which OpenJFX version they were written against for that reason.

The threading model deserves its own mention, because it is where a working prototype turns into a frozen window. Every node must be created and modified on the JavaFX Application Thread, and anything slow, whether a network call, a query or a file read, has to leave that thread and post its result back. A Task gives you the success and failure callbacks on the right thread for free, which is why it appears in these guides more often than a raw thread does.

The other recurring theme is that the toolkit rewards binding over event handling. Wiring a label to a property means the label cannot drift out of step with the value; wiring it with a listener means it can, and eventually will.

Packaging is the last thing most JavaFX projects deal with and the first thing a user sees. Since the toolkit left the JDK, shipping an application means either asking the recipient to install a JDK with JavaFX in it, which is not a reasonable ask, or building a runtime image with jlink and wrapping it with jpackage into a real installer. Those steps are covered where they belong rather than as an appendix, because they change how the project is structured from the start.

All JavaFX tutorials

Frequently asked questions

Is JavaFX still part of the JDK?

No. It was removed after Java 10 and is now a separate dependency, which is why the build configuration is shown in every guide.

Can I style JavaFX with CSS?

Yes, with a JavaFX-specific dialect — properties are prefixed `-fx-` and the selector support is narrower than on the web.

Should I use FXML or build the UI in code?

Both are covered. FXML separates structure from behaviour and suits larger interfaces; code is more direct for small ones.

How does JavaFX compare to Swing?

JavaFX has a modern property and binding model, CSS styling and hardware-accelerated rendering. Swing is still supported but is no longer where the toolkit is going.

Which layout pane should I use?

BorderPane for an application shell, GridPane for forms, VBox and HBox for simple stacks. AnchorPane last — absolute positioning stops resizing sensibly.

What is a JavaFX property?

An observable value that other values can bind to, so derived state updates automatically instead of through listener code you maintain by hand.