Search code examples
swingjavafxjxbrowser

Text selection from mouse does not work


I have a simple Hello world HTML page displayed using a JxBrowser embedded on a JavaFX component. I am using the Lightweight accelerated mode (lightweight_accelerated)

Code looks like this :

FXCanvas fxComposite = new FXCanvas(parent, SWT.EMBEDDED | SWT.NO_BACKGROUND);
Browser browser = new Browser(BrowserType.LIGHTWEIGHT);
com.teamdev.jxbrowser.chromium.javafx.BrowserView view = new com.teamdev.jxbrowser.chromium.javafx.BrowserView(
                browser);
fxComposite.setScene(FXResourceManager.createScene(view));
browser.setHtml("<p>Hello <span>World!</span></p>");

Text selection works fine when using CTRL + A shortcut or when a word is double-clicked, but it does not when I try to do a "mouse selection" (e.g. selecting "Hell").

I found out that it does work if I switch to HEAVYWEIGHT mode or if I use SWING component instead.

Is there a way to make it work with both JavaFx component and LIGHTWEIGHT (accelerated mode)?


Solution

  • In fact, it has nothing to do with JxBrowser. This behaviour is caused by a known JavaFx bug : https://bugs.openjdk.java.net/browse/JDK-8096818

    It has been fixed in version 8u60 (released in 2015).