Carla
Carla

Reputation: 3380

Problems building a JavaFX application

I'm trying to upgrade a very old JavaFX application which uses in the [Main][1] view a set of controls from the packages javafx.scene such as javafx.scene.SceneBuilder or javafx.scene.control.TextField. I have added the following dependency in the pom.xml:

<dependency>
  <groupId>org.openjfx</groupId>
  <artifactId>javafx-controls</artifactId>
  <version>17.0.1</version>
</dependency>

However, when I try to build the project, all Classes in the javafx.scene packages are not found.

Is there a separate dependency to add for this package ? According to the product docs, only the above is mentioned. Any help? Thanks [1]: https://github.com/fmarchioni/jboss-as-quickstart/blob/master/kitchensink-javafx/src/main/java/org/kitchensinkfx/view/Main.java

Upvotes: 1

Views: 184

Answers (1)

jewelsea
jewelsea

Reputation: 159291

See the getting started instructions at openjfx.io.

Modularity

When JavaFX was modularized and separated from the jdk in Java 11, previous code which relied on JavaFX being in the jdk stopped working. You need to provide the JavaFX modules and instructions on how to use them to the javac and java processes.

This class:

javafx.scene.control.TextField

Does exist in a modern JavaFX distribution. But, to use it, you must either place

requires javafx.controls;

In a module-info.java file you add.

OR

Add the javafx.controls module via a command line switch.

Either way, the appropriate JavaFX modules (javafx.controls, javafx.graphics, etc.) need to also be on your module path.

The Java module system is complex and its use varies by environment. To better understand, study a tutorial on the module system and the openjfx.io documentation.

Builders

The builder classes were deprecated and removed.

You need to change the code to use a constructor and relevant method calls on the constructed instance.

This class:

javafx.scene.SceneBuilder

No longer exists in a modern JavaFX distribution and its usage must be replaced as described above.

Suggested approach

If using Idea, I recommend following this:

Upvotes: 2

Related Questions