Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Package javafx.embed.swing missing from JavaFX 12?

I upgraded from Java 10 to Java 12 and JavaFX 12.

Now I can't compile my project anymore because javafx.embed.swingSwingFXUtils is no longer recognized.

Intellij can't find any library for the class. Seems like javafx.embed doesn't exist anymore.

I looked to see if the package was dropped but I couldn't find any information regarding it.

like image 983
Guillaume F. Avatar asked Sep 04 '19 04:09

Guillaume F.


People also ask

How to embed JavaFX in Swing?

Adding JavaFX Content to a Swing ComponentCreating an instance of the JFXPanel class implicitly starts the JavaFX runtime. After the GUI is created, call the initFX method to create the JavaFX scene on the JavaFX application thread.

How do I fix Java package JavaFX application does not exist?

The JavaFX package is not included in JDK 9 and later. You need to install JDK 8, or you can add the JavaFX package separately, for example, from JDK 8 ( jfxrt. jar ).

Can you mix JavaFX and Swing?

As its already been said, it is possible to mix Swing and JavaFX especially since Java 8 you can do it both ways: Embed Swing Components in JavaFX with SwingNode.


2 Answers

The module javafx.swing needs to be included in the gradle file:

javafx {
    modules = [ 'javafx.controls', 'javafx.graphics', 'javafx.swing', 'javafx.base' ]
}
like image 79
Guillaume F. Avatar answered Oct 29 '22 12:10

Guillaume F.


In my case, a file called module-info.java was generated in the same package. There I had to add

requires javafx.swing;

When building again, the class was found.

like image 21
david-1160 Avatar answered Oct 29 '22 14:10

david-1160