Currently I am testing some features of ControlsFX for fun and it works fine with the exception of the AutoCompletionBinding.
It gives me the following module error, which is commonly known:
Caused by: java.lang.IllegalAccessError: class org.controlsfx.control.textfield.AutoCompletionBinding (in module org.controlsfx.controls) cannot access class com.sun.javafx.event.EventHandlerManager (in module javafx.base) because module javafx.base does not export com.sun.javafx.event to module org.controlsfx.controls
at org.controlsfx.controls/org.controlsfx.control.textfield.AutoCompletionBinding.<init>(AutoCompletionBinding.java:525)
at org.controlsfx.controls/impl.org.controlsfx.autocompletion.AutoCompletionTextFieldBinding.<init>(AutoCompletionTextFieldBinding.java:107)
at org.controlsfx.controls/impl.org.controlsfx.autocompletion.AutoCompletionTextFieldBinding.<init>(AutoCompletionTextFieldBinding.java:92)
at org.controlsfx.controls/org.controlsfx.control.textfield.TextFields.bindAutoCompletion(TextFields.java:187)
at org.controlsfx.controls/org.controlsfx.control.textfield.TextFields.bindAutoCompletion(TextFields.java:181)
at org.mycompany@1.0-SNAPSHOT/org.mycompany.PrimaryController.initialize(PrimaryController.java:23) [...]
From e. g. this wiki entry I know that this vm option is needed:
--add-exports=javafx.base/com.sun.javafx.event=org.controlsfx.controls
But still I can’t figure out how to get it to work in my modular project build with Maven (JavaFX and IntelliJ).
Here is where I am now:
Controller class:
package org.mycompany;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TextField;
import org.controlsfx.control.textfield.TextFields;
public class PrimaryController implements Initializable {
@FXML
private TextField textField;
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
String[] suggestions = new String[]{"Aaaa", "Abaa", "abba"};
TextFields.bindAutoCompletion(textField, suggestions);
}
}
FXML file:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.VBox?>
<VBox xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.mycompany.PrimaryController">
<children>
<TextField fx:id="textField" />
</children>
</VBox>
module-info.java:
module ControlsFXTest {
requires javafx.controls;
requires javafx.fxml;
requires org.controlsfx.controls;
opens org.mycompany to javafx.fxml;
exports org.mycompany;
}
pom file:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.mycompany</groupId>
<artifactId>ControlsFXTest</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>14</maven.compiler.source>
<maven.compiler.target>14</maven.compiler.target>
<javafx.version>14.0.1</javafx.version>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>${javafx.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.controlsfx/controlsfx -->
<dependency>
<groupId>org.controlsfx</groupId>
<artifactId>controlsfx</artifactId>
<version>11.0.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>14</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.4</version>
<configuration>
<mainClass>org.mycompany.App</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
I tried several things, e. g. adding the following to the compiler plugin configuration, but nothing for now made it work.
<compilerArgs>
<arg>--add-exports=javafx.base/com.sun.javafx.event=org.controlsfx.controls</arg>
</compilerArgs>
Does anyone know what I need to do at this point? Thank you for your help in advance.