Problems with touch input and OpenJDK 11 with JavaFX 11

只愿长相守 提交于 2021-02-18 10:41:08

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/53852043/problems-with-touch-input-and-openjdk-11-with-javafx-11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!