JavaFX is a modern UI toolkit built around a scene graph, FXML, CSS styling, property binding and hardware-accelerated rendering. Swing is the older toolkit that ships inside the JDK and uses lightweight components drawn by Java. For a new desktop application JavaFX is usually the better choice, while Swing remains valid for maintaining existing code.
One important fact changed the picture: JavaFX was removed from the JDK in Java 11 and now lives in the OpenJFX project, released separately from the JDK. Swing is still part of the java.desktop module.
Swing builds the UI from JComponent objects (JFrame, JPanel, JButton) and paints them in an immediate-mode style on the Event Dispatch Thread (EDT). JavaFX uses a retained-mode scene graph: a Stage holds a Scene, which holds a tree of Node objects. The renderer (Prism) can use the GPU and caches the node tree, which makes animation and effects cheaper.
| Aspect | Swing | JavaFX |
|---|---|---|
| Distribution | Part of the JDK (java.desktop) | Separate OpenJFX modules (javafx.controls, javafx.fxml and others) |
| UI model | Component hierarchy, painted by paintComponent | Scene graph of Node objects |
| Threading | Event Dispatch Thread | JavaFX Application Thread |
| Styling | Look and feel classes (Metal, Nimbus, third-party) | CSS files and inline styles |
| Layout declaration | Code, with layout managers | Code or FXML plus Scene Builder |
| Data binding | Manual listeners | Built-in observable properties and binding |
| Animation | Timers and custom painting | Timeline, Transition, AnimationTimer |
| Graphics | Java2D | Prism pipeline, Canvas, effects, 3D |
Swing:
JavaFX:
The JavaFX label is bound to a property, so there is no manual update code. To run it you need the OpenJFX SDK or a Maven or Gradle plugin, for example org.openjfx:javafx-controls with the javafx-maven-plugin, and --module-path plus --add-modules javafx.controls when launching by hand.
StringProperty, ObservableList and bind keep UI and model in sync..css files and style classes, including theming at runtime.TableView, TreeTableView, charts, WebView, media playback, Canvas, effects such as blur and drop shadow, and 3D shapes.FadeTransition, TranslateTransition, Timeline and AnimationTimer.Swing has been stable for more than two decades and is still maintained as part of the JDK, but it receives only fixes and minor updates, not new features.
Its drawbacks are verbose code, no built-in binding and CSS, and a dated default look.
You do not have to rewrite everything at once. JFXPanel embeds JavaFX content inside a Swing window, and SwingNode embeds Swing components inside a JavaFX scene. Both toolkits have their own UI thread, so move work between them with Platform.runLater (JavaFX) and SwingUtilities.invokeLater (Swing).
A practical migration path is to embed new screens in JavaFX through JFXPanel while keeping the old shell, and move screen by screen. Packaging is handled by jpackage, which creates native installers and bundles the runtime with the JavaFX modules.
No. It is actively developed as OpenJFX with regular releases aligned to the JDK schedule. It was only removed from the JDK distribution in Java 11.
No. Swing is still part of the JDK, but it is in maintenance mode.
Yes, through JFXPanel and SwingNode, as long as you respect each toolkit's UI thread.
JavaFX, unless you depend on a Swing-only library or must stay with an existing Swing code base.
JavaFX offers a scene graph, CSS, FXML, binding, animation and GPU rendering, which makes modern UIs much easier than in Swing. Swing is mature and bundled with the JDK, and remains practical for legacy applications. Choose JavaFX for new work, keep Swing where it already works, and bridge the two with JFXPanel or SwingNode when migrating.