jln*_*-ho 8 java javafx touch openjfx
我正在一个JavaFX项目上,想从Oracle JDK 1.8切换到OpenJDK11。到目前为止,过渡是无缝的,但是与触摸/鼠标输入有关的一个主要问题仍然引起麻烦。
JavaFX UI应该在支持触摸的设备上运行,该设备以前可以与Oracle JDK 1.8一起直接使用。当我触摸屏幕时,将按预期触发以下鼠标事件序列:
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();
}
}
}
Run Code Online (Sandbox Code Playgroud)
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:
xinput): Atmel maXTouch DigitizerThe 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
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
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的两种不同状态,所以也许在另一个触摸屏上两种事件类型的状态字段都相同吗?
小智 1
我的触摸屏和 JFX 也遇到了同样的问题。我的代码在 Open JDK 1.8 及其相应的 JFX 上运行良好,在 OpenJDK 11 及其相应的 JFX 上运行失败。它与 Liberica 的 JDK 和 JFX 配合良好 https://bell-sw.com/pages/java-11.0.7-for-Embedded/
所以对我来说,我的解决方法是更改为 Liberica JDK 11 和 JFX 发行版。其他选项可能是来自 Azul 或 Corretto 的 JDK、JFX 发行版。