[英]Use only JavaFX touch events in Swing Application
Is there a way to use the JavaFX touch events in a swing application? 有没有办法在swing应用程序中使用JavaFX触摸事件? Currently I am using a JFXPanel to capture the JavaFX events, however when I try to get the events I am not receving any touch events and only mouse events instead.
目前我正在使用JFXPanel捕获JavaFX事件,但是当我尝试获取事件时,我不会接收任何触摸事件而只接收鼠标事件。 This is tested on a Windows 8.1 Dell Touch Screen.
这是在Windows 8.1 Dell触摸屏上测试的。
Updated: The code below is the skeleton of what I am using to get the events. 更新:下面的代码是我用来获取事件的框架。 This JFXPanel is used as a glasspane in the Swing application.
此JFXPanel用作Swing应用程序中的glasspane。 This creates a JFXPanel for the glasspane, which is able to capture all the events.
这将为glasspane创建一个JFXPanel,它可以捕获所有事件。
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);
}
}
This question on the FX mailing list suggests it is not possible using the approach you've taken, instead you'll need to create a JavaFX stage and embed your Swing application using SwingNode (Swing in FX) instead of JFXPanel (FX in Swing). FX邮件列表上的这个问题表明你不可能使用你所采用的方法,而是你需要创建一个JavaFX阶段并使用SwingNode(Swing in FX)而不是JFXPanel(Swing中的FX)嵌入你的Swing应用程序。
I've not got any touch enabled 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();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.