Julekk
Julekk

Reputation: 31

Problem with webEngine JavaFX using with swing

I'm trying to load browser using JavaFX WebEnginge to swing as below

SwingUtilities.invokeLater(() -> InitGUI());
final JFXPanel jfxPanel = new JFXPanel();
panel.add(jfxPanel);

Platform.runLater(() -> {
    WebView webView = new WebView();
    jfxPanel.setScene(new Scene(webView));
    webView.getEngine().load("https://pl.wikipedia.org/wiki/London");
});

Websites shows in my swing application but when I'm moving a mouse on the loaded website IntelliJ throws

Exception in thread "AWT-EventQueue-0" java.lang.NoSuchMethodError: 'void com.sun.javafx.embed.EmbeddedSceneInterface.mouseEvent(int, int, boolean, boolean, boolean, int, int, int, int, boolean, boolean, boolean, boolean, boolean)'
    at javafx.embed.swing.JFXPanel.sendMouseEventToFX(JFXPanel.java:426)
    at javafx.embed.swing.JFXPanel.processMouseEvent(JFXPanel.java:465)
    at java.desktop/java.awt.Component.processEvent(Component.java:6401)
    at java.desktop/java.awt.Container.processEvent(Container.java:2263)
    at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5012)
    at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
    at java.desktop/java.awt.Component.dispatchEvent(Component.java:4844)
    at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4919)
    at java.desktop/java.awt.LightweightDispatcher.retargetMouseEnterExit(Container.java:4691)
    at java.desktop/java.awt.LightweightDispatcher.trackMouseEnterExit(Container.java:4677)
    at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4528)
    at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4489)
    at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307)
    at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2764)
    at java.desktop/java.awt.Component.dispatchEvent(Component.java:4844)
    at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
    at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
    at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
    at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

I should add mouseEventListeners somewhere? Whole GUI is in my Main class, without any buttons, just JLabels and this webView from javaFX. Error occurs only on this webView every time I move mouse/click. Other swing components don't throw anything.

@edit I haven't posted first line of exception

Exception in thread "AWT-EventQueue-0" java.lang.NoSuchMethodError: 'void com.sun.javafx.embed.EmbeddedSceneInterface.mouseEvent(int, int, boolean, boolean, boolean, int, int, int, int, boolean, boolean, boolean, boolean, boolean)'

Upvotes: 1

Views: 316

Answers (3)

david-1160
david-1160

Reputation: 112

I am building with Maven, and my solution also had something to do with versions of dependencies, but instead of deleting the version, I upgraded every javafx library to the newest available version. Before that older versions were used which were the cause of the problem so in pom.xml I edited the <version> tags.

Before:

        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>13</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>13</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-swing</artifactId>
            <version>11</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-base</artifactId>
            <version>13</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-graphics</artifactId>
            <version>13</version>

After:

        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>17.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>17.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-swing</artifactId>
            <version>17.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-base</artifactId>
            <version>17.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-graphics</artifactId>
            <version>17.0.1</version>
        </dependency>

Upvotes: 0

Brad Turek
Brad Turek

Reputation: 2852

Adding the modules didn't solve it for me—I had already added them.

A Solution

Not specifying a JavaFX version in the JavaFX Gradle Plugin solved it for me.

javafx {
    version = "11.0.1" // ← I removed this line
    modules = [ 'javafx.controls', ...
}

Details

I was trying to use CalendarFX; turns out the version I was trying to use, 11.8.3, uses JavaFX 13.0.1.

Once I upped or removed the JavaFX version I was including, the exception went away.

Full Exception

Exception in thread "AWT-EventQueue-0" java.lang.NoSuchMethodError: 'void com.sun.javafx.embed.EmbeddedSceneInterface.mouseEvent(int, int, boolean, boolean, boolean, int, int, int, int, boolean, boolean, boolean, boolean, boolean)'
    at javafx.swing/javafx.embed.swing.JFXPanel.sendMouseEventToFX(JFXPanel.java:426)
    at javafx.swing/javafx.embed.swing.JFXPanel.processMouseEvent(JFXPanel.java:465)
    at java.desktop/java.awt.Component.processEvent(Component.java:6400)
    at java.desktop/java.awt.Container.processEvent(Container.java:2263)
    at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5011)
    at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
    at java.desktop/java.awt.Component.dispatchEvent(Component.java:4843)
    at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4918)
    at java.desktop/java.awt.LightweightDispatcher.retargetMouseEnterExit(Container.java:4698)
    at java.desktop/java.awt.LightweightDispatcher.trackMouseEnterExit(Container.java:4676)
    at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4527)
    at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4488)
    at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307)
    at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2772)
    at java.desktop/java.awt.Component.dispatchEvent(Component.java:4843)
    at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
    at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
    at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
    at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

Upvotes: 0

Julekk
Julekk

Reputation: 31

Problem solved

I've added

--module-path /Users/<user>/javafx-sdk-15/lib --add-modules=javafx.controls,javafx.fxml,javafx.web,javafx.swing

in Run>Edit Configurations>VM options

Upvotes: 1

Related Questions