Issue
My setup:
- JavaFX SDK 18.0.1
- Windows 11
- JDK 18.0.1.1
- A screen with the touch support
When I try a simple program, none of the touch events are triggered upon touch gestures. My test app follows.
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.input.TouchEvent;
import javafx.stage.Stage;
public class JavaFXSandbox extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) throws Exception {
Group root = new Group();
Scene scene = new Scene(root, 600, 600);
Canvas canvas = new Canvas(600, 600);
root.getChildren().add(canvas);
stage.addEventFilter(TouchEvent.ANY, e -> System.out.println("touch event: " + e));
stage.setScene(scene);
stage.show();
}
}
Is there any way of circumventing the issue, or am I misusing the JavaFX API?
Solution
After playing a bit with JavaFX, I found out that touch events are converted to mouse events such, that it's possible to simulate touch events in mouse listeners.
Answered By - coderodde
Answer Checked By - Senaida (JavaFixing Volunteer)