IllegalAccessError when using ControlsFX AutoCompletionBinding

59 Views Asked by At

I am getting an 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

when using ControlsFX AutoCompletionBinding with

try {

                    SearchSession searchSession = Search.session(JpaUtil.getEntityManager());

                    SearchResult<Student> result = searchSession.search(Student.class)
                            .where(f -> f.match()
                                    .field("firstName")
                                    .matching(search))
                            .fetch(20);

                    List<Student> list = result.hits();
                    TextFields.bindAutoCompletion(searchField, list);

                } catch (Exception ex) {
                    ex.printStackTrace();
                }

I am trying to implement an autosuggestion search field (searching in the DB as you type). I am using JDK17. It is related to the modularity of Java but how can I fix that? Thanks.

1

There are 1 best solutions below

0
Marko On BEST ANSWER

Add the following plugin to your pom.xml file to configure the JavaFX runtime:

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>11</release>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.3</version>
                <configuration>
                    <mainClass>com.xxx.hellojavafx.Main</mainClass>
                    <options>
                        <option>-XX:+UseG1GC</option>
                        <option>--add-exports</option>
                        <option>javafx.base/com.sun.javafx.event=org.controlsfx.controls</option>
                    </options>
                </configuration>
            </plugin>
        </plugins>
    </build>