As explained in the Introduction of this chapter, the Swing GUI framework has evolved into a set of rich GUI components, which developers have come to love over the years. Suppose, however, you want to continue using Swing in your JavaFX application; what do you do? This recipe shows you how to use the JavaFX wrapper APIs for Swing to embed Swing components in JavaFX scripts.
The JavaFX Swing wrapper classes let developers embed Swing components directly into JavaFX applications. The wrapper API can be found in the package javafx.ext.swing
. For this recipe, it is assumed that you are familiar with using Swing components. It will also be helpful to be familiar with JavaFX's Control API. To illustrate how to embed Swing components in JavaFX, we have converted the data form introduced in the recipe Creating a form with JavaFX controls, to use all Swing components.