Use only JavaFX touch events in a Swing application

Is there a way to use JavaFX touch events in a swing application? I am currently using JFXPanel to capture JavaFX events, however, when I try to receive events, I do not receive any touch events and only mouse events. This is tested on the Dell Windows 8.1 Dell Touchscreen.

Updated: The code below is the skeleton of what I use to receive events. This JFXPanel is used as glass glass in a Swing application. This creates a JFXPanel for glass glass that is capable of capturing all events.

public class MouseEventRouter extends JFXPanel { ... public ZeusMouseEventRouter(JMenuBar menuBar, Container contentPane) { ... this._contentPane = contentPane; this._contentPane.add(_JFXpanel); this._contentPane.setVisible(true); init(); } private void init() { pane = new VBox(); pane.setAlignment(Pos.CENTER); Platform.runLater(this::createScene); } private void createScene() { Scene scene = new Scene(pane); ... scene.setOnTouchPressed(new EventHandler<javafx.scene.input.TouchEvent>() { @Override public void handle(javafx.scene.input.TouchEvent event) { System.out.println("tap down detected"); } }); ... setScene(scene); } } 
+7
java swing javafx
source share
1 answer

This question on the FX mailing list suggests that this is not possible using the approach you did, instead you will need to create JavaFX and implement the Swing application using SwingNode (Swing in FX) instead of JFXPanel (FX in Swing).

I don't have touch screen hardware to test this, but I expect the following to work ...

 public class TouchApp extends Application { public static void main(String[] args) { launch(args); } @Override public void start(Stage primaryStage) throws Exception { JPanel swingContent = new JPanel(); swingContent.add(new JButton("Hello world")); swingContent.add(new JScrollBar()); BorderPane content = new BorderPane(); SwingNode swingNode = new SwingNode(); swingNode.setContent(swingContent); content.setCenter(swingNode); Scene scene = new Scene(content); scene.setOnTouchPressed((e) -> { System.out.println(e); }); primaryStage.setScene(scene); primaryStage.show(); } } 
+3
source share

All Articles