0

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.

anko
  • 1,628
  • 1
  • 6
  • 14
  • 1
    How are you executing your project, via Maven (e.g. `exec-maven-plugin` or `javafx-maven-plugin`) or via the IDE? – Slaw Jun 29 '20 at 02:27
  • Well, now with the use of Maven I do `javafx:run` (it does not show `exec:java` for this project), so I guess it is the `javafx-maven-plugin`?! Uselly I used the IDE way. I tried it also for this project, but it did not work as well. :( – anko Jun 29 '20 at 03:21
  • 1
    You can configure the run configurations in your IDE to delegate to Maven. And check out the [readme](https://github.com/openjfx/javafx-maven-plugin#javafxrun-options)) of the `javafx-maven-plugin`; it shows how to add `--add-exports` options and such. – Slaw Jun 29 '20 at 03:50
  • Okay, with the right `javafx-maven-plugin’ config (‘ – anko Jun 29 '20 at 12:28
  • 1
    In your question you're configuring the compiler plugin but the error occurs at runtime. When you configure `javafx:run` you're adding the option at runtime. I believe that's why it works for you now. As for `jlink`, it unfortunately does not let you set options or arguments for the application (I wish it did). But you can do that with `jpackage` with `--java-options` and `--arguments`. – Slaw Jun 29 '20 at 12:58
  • Yeah, with `jpackage` it works for me without a propblem. Thanks again! – anko Jun 29 '20 at 13:07

0 Answers0