Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems with touch input and OpenJDK 11 with JavaFX 11

I'm working on a JavaFX project and would like to switch from Oracle JDK 1.8 to OpenJDK 11. So far the transition has been pretty seamless, but there is still one main problem related to touch/mouse input that's causing some trouble.

The JavaFX UI is supposed to run on a touch-enabled device, which used to work straight out of the box with Oracle JDK 1.8. When I touch the screen, the following sequence of mouse events is fired as expected:

MOUSE_PRESSED

MOUSE_RELEASED

MOUSE_CLICKED

After building the same application with OpenJDK11 (using OpenJFX 11 as an external library as JavaFX is no longer part of the JDK by default) I get the follwing sequence of events:

MOUSE_ENTERED_TARGET

MOUSE_ENTERED_TARGET

MOUSE_EXITED_TARGET

MOUSE_EXITED_TARGET

This explains why I can't click any buttons (or controls in general). So far so good. The question is, how do I get my MOUSE_{PRESSED,RELEASED,CLICKED} events back?

SSCE:

package com.example.jfxtouchtest;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.input.MouseEvent;
import javafx.scene.input.TouchEvent;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;


public class JFXTouchTest {

    public static void main(String[] args) {
        Application.launch(JFXApp.class, args);
    }

    public static class JFXApp extends Application {
        @Override
        public void start(Stage primaryStage) {
            primaryStage.addEventFilter(TouchEvent.ANY, e -> System.out.println("touch event: " + e.getEventType()));
            primaryStage.addEventFilter(MouseEvent.ANY, e -> System.out.println("mouse event: " + e.getEventType()));
            primaryStage.setScene(new Scene(new Pane()));
            primaryStage.setWidth(800);
            primaryStage.setHeight(600);
            primaryStage.show();
        }
    }
}

I think it's worth noting that all fired events are MouseEvents (not TouchEvents), regardless of whether I'm using the touchscreen or not. That in itself is sort of strange in my opinion, but at least I'm getting the desired behaviour with JDK 8...

Some background information:

  • OS: Ubuntu 18.04.01 LTS
  • Kernel: 4.15.0-42-generic
  • Oracle JDK 1.8.0_191
  • OpenJDK 11.0.1
  • Touchscreen (as reported by xinput): Atmel maXTouch Digitizer
  • The touchscreen works just fine with other applications, click events seem to be handled as expected.
  • The somehwat related VM-arguments

    -Dcom.sun.javafx.isEmbedded=true and

    -Dcom.sun.javafx.touch=true

    both seem to have no effect on the issue

  • There seems to be a slight difference in the xev output I'm getting depending on whether I'm using the mouse or the touchscreen:

    Mouse (state is 0x0 for ButtonPress, 0x100 for ButtonRelease):

    ButtonPress event, serial 34, synthetic NO, window 0x3400001,
        root 0x193, subw 0x0, time 16982696, (93,90), root:(964,612),
        state 0x0, button 1, same_screen YES
    
    ButtonRelease event, serial 34, synthetic NO, window 0x3400001,
        root 0x193, subw 0x0, time 16983364, (93,90), root:(964,612),
        state 0x100, button 1, same_screen YES
    

    Touchscreen (state is 0x100 in both cases):

    ButtonPress event, serial 34, synthetic NO, window 0x3400001,
        root 0x193, subw 0x0, time 17599475, (93,145), root:(964,667),
        state 0x100, button 1, same_screen YES
    
    ButtonRelease event, serial 34, synthetic NO, window 0x3400001,
        root 0x193, subw 0x0, time 17599537, (93,145), root:(964,667),
        state 0x100, button 1, same_screen YES
    

    I'm not exactly sure what this means, though.

Any help would be greatly appreciated, even if it's just a confirmation that the issue is reproducible on another machine with another type of touchscreen! Many thanks in advance!

UPDATE: I have managed to get my hands on a different touchscreen in the meantime, and it seems to work fine with that one. What's interesting is that, just like with regular mouse events, xev reports two different states for ButtonPress and ButtonRelease, so maybe the state field being the same for both event types on the other touchscreen has something to do with this after all?

like image 790
jln-ho Avatar asked Dec 19 '18 13:12

jln-ho


People also ask

Does JavaFX work with Java 11?

In Java 11, JavaFX was removed from the SDK. It is now in its own separate module, and if you want to use it in your application you will need to specifically include it.

Does OpenJDK 11 include JavaFX?

JavaFX is not part of most JDK 11+ downloads, it is usually downloaded by developers as modules or a separate SDK. Specifically for JavaFX 11+, as detailed on the https://openjfx.io site: JavaFX runtime is available as a platform-specific SDK, or as a number of jmods, or as a set of artifacts in Maven Central.

Does JavaFX work with OpenJDK?

JavaFX (OpenJFX)JavaFX lives on as OpenJFX, an OpenJDK subproject.

Why is JavaFX no longer supported?

JavaFX was removed from JDK since JDK 11. Since JDK 9, java is modular. JavaFX was split into modules. Hence there is no longer a single jfxrt.


1 Answers

I had the same problem with my touch screen and JFX. My code works fine with Open JDK 1.8 and its corresponding JFX, it fails with OpenJDK 11 and its corresponding JFX. It works fine with the JDK and JFX from Liberica https://bell-sw.com/pages/java-11.0.7-for-Embedded/

So for me my workaround was to change to the Liberica JDK 11 and JFX distribution. Other options may be JDK, JFX distributions from Azul or Corretto.

like image 112
demch Avatar answered Sep 28 '22 06:09

demch