触摸输入和带有JavaFX 11的OpenJDK 11的问题 [英] Problems with touch input and OpenJDK 11 with JavaFX 11

查看:123
本文介绍了触摸输入和带有JavaFX 11的OpenJDK 11的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究JavaFX项目,并希望从Oracle JDK 1.8切换到OpenJDK11.到目前为止,过渡是无缝的,但是仍然存在与触摸/鼠标输入有关的一个主要问题,这会引起一些麻烦. .

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.

JavaFX UI应该在支持触摸的设备上运行,该设备以前可以与Oracle JDK 1.8一起使用.当我触摸屏幕时,将按预期触发以下鼠标事件序列:

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

在使用OpenJDK11构建相同的应用程序之后(将OpenJFX 11用作外部库,因为JavaFX默认不再是JDK的一部分),我得到了以下事件序列:

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

这说明了为什么我无法单击任何按钮(或一般的控件).到目前为止,一切都很好.问题是,如何恢复我的MOUSE_{PRESSED,RELEASED,CLICKED}事件?

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();
        }
    }
}

我认为值得注意的是,所有触发事件都是MouseEvents(不是TouchEvents),无论我是否使用触摸屏.在我看来,这本身有点奇怪,但是至少我在使用JDK 8时获得了预期的行为...

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...

一些背景信息:

  • 操作系统:Ubuntu 18.04.01 LTS
  • 内核:4.15.0-42通用
  • Oracle JDK 1.8.0_191
  • OpenJDK 11.0.1
  • 触摸屏(由xinput报告):Atmel maXTouch Digitizer
  • 触摸屏可以与其他应用程序很好地工作,单击事件似乎已按预期处理.
  • 与虚拟机有关的某些参数

  • 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

-Dcom.sun.javafx.touch=true

似乎都对这个问题没有影响

both seem to have no effect on the issue

根据使用的是鼠标还是触摸屏,我得到的xev输出似乎略有不同:

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:

鼠标(对于ButtonPress,state0x0,对于ButtonRelease,0x100):

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

触摸屏(在两种情况下,state均为0x100):

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!

更新:在此期间,我已经设法将手放在其他触摸屏上,并且似乎可以很好地工作.有趣的是,就像常规的鼠标事件一样,xev报告ButtonPress和ButtonRelease的两个不同状态,所以也许另一个触摸屏上两个事件类型的状态字段都与此有关?

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?

推荐答案

我的触摸屏和JFX遇到相同的问题.我的代码可以在Open JDK 1.8及其对应的JFX上正常运行,而在OpenJDK 11及其对应的JFX上则无法运行.它可以与Liberica https://bell的JDK和JFX一起很好地工作. -sw.com/pages/java-11.0.7-for-Embedded/

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/

所以对我来说,我的解决方法是更改​​为Liberica JDK 11和JFX发行版. 其他选项可能是JDK,Azul或Corretto的JFX发行版.

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.

这篇关于触摸输入和带有JavaFX 11的OpenJDK 11的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆