intellij-ideajavafxcontrolsfx

JavaFX - IntelliJ don't recognize ControlsFX library control


I'm trying to use the MaskerPane control from the ControlsFX library. I installed the library in Scene Builder, inserted the MaskerPane control into a container and it's working.

enter image description here

enter image description here

However, even after importing the library, IntelliJ doesn't recognize the control.

enter image description here

It asks me to import it via Maven, even though I've already done exactly that.

enter image description here

Thank you in advance.

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>PaneTeste</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>PaneTeste</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <junit.version>5.9.2</junit.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>17.0.6</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>17.0.6</version>
        </dependency>

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.controlsfx</groupId>
            <artifactId>controlsfx</artifactId>
            <version>11.1.2</version>
        </dependency>
        <dependency>
            <groupId>org.controlsfx</groupId>
            <artifactId>controlsfx</artifactId>
            <version>11.1.2</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.11.0</version>
                <configuration>
                    <source>17</source>
                    <target>17</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.8</version>
                <executions>
                    <execution>
                        <!-- Default configuration for running with: mvn clean javafx:run -->
                        <id>default-cli</id>
                        <configuration>
                            <mainClass>com.example.paneteste/com.example.gridpanetest.GridCenterApplication</mainClass>
                            <launcher>app</launcher>
                            <jlinkZipName>app</jlinkZipName>
                            <jlinkImageName>app</jlinkImageName>
                            <noManPages>true</noManPages>
                            <stripDebug>true</stripDebug>
                            <noHeaderFiles>true</noHeaderFiles>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Solution

  • Correctly define your Java modules

    Most likely your issue is that you have used a module-info.java (not shown in the question) and have not added a requirement to use the controlsfx library.

    You can see from the ControlsFX documentation that the module's name is org.controlsfx.controls.

    To use the module you need this entry in your module-info.java:

    requires org.controlsfx.controls;
    

    See Understanding Java Modules for more information.

    Some ControlsFX controls are not written to work seamlessly with the Java module system. Make sure you read and understand the wiki page on using ControlsFX with the module system and apply any learnings to your usage:

    Note: that JDK 9+ ControlsFX article references VM options, which can be tricky to set in Idea.

    Unrelated

    Don't manually add a library that is a managed Maven dependency. Remove the manually added libraries and sync the Maven and Idea projects instead.

    Manage all your dependencies using Maven (don't manually add jfoenix either; define the dependency in the pom file).

    jfoenix is unmaintained and problematic when combined with modern JavaFX distributions, consider MaterialFX instead.

    If you create a new project in Idea (2024 version), I think it gives you an option of adding ControlsFX. So you can try that and compare the created project (especially the module-info.java) with your own project.