目前,我正在为 Raspberry Pi 3 开发 JavaFX 应用程序。为了在我的 PC 上进行开发,我使用 Ubuntu 16.04.1、OpenJDK 1.8.0_111 和 OpenJFX 8.0.60。为了在 Raspberri Pi 上运行,我使用 Raspbian Jessie 和 PIXEL(以控制台模式启动)、OpenJDK 1.8.0_40 和 OpenJFX 8.0.60。
图形鼠标光标是不必要的,因为用户应该只使用触摸屏与应用程序交互。此外,鼠标光标很烦人,因为它稍微覆盖了屏幕内容。此外,每当触摸屏幕时,它都会通过改变位置来刺激用户。因此我想隐藏屏幕上的鼠标光标。
在我的电脑上,我可以使用以下代码隐藏鼠标光标:
scene.setCursor(Cursor.NONE);
我使用 bash shell 在 Raspberry Pi 上启动应用程序
java -jar MyApp.jar
这样做之后,setCurser 属性开始工作。但是在触摸屏幕或移动鼠标后,默认的鼠标光标出现在屏幕上。这似乎是一个 Unresolved 问题:Post on raspberrypi.org forum
Note that the default configuration of JavaFX on the Raspberry Pi does not use X11. Instead JavaFX works directly with the display framebuffer and input devices. So you should not have the X11 desktop running when starting JavaFX.
作为解决方法,我如何在 Raspbian Jessie 上的帧缓冲区中隐藏图形鼠标光标?
最佳答案
我已经找到解决此错误的方法。虽然它在我的应用程序开始时会产生一些闪烁,但在我的情况下是可以接受的。 (也可以尝试在程序启动时关闭背光) 这是神奇的代码(治愈效果是在几个全屏窗口工作时不小心发现的)
private void fixMouse(Stage primaryStage)
{
Platform.runLater(()->{
//Show mouse cursor
Robot robot = com.sun.glass.ui.Application.GetApplication().createRobot();
robot.mouseMove(790,470);
robot.destroy();
//Show fullscreen dialog
final Stage dialog = new Stage();
dialog.initModality(Modality.APPLICATION_MODAL);
dialog.initOwner(primaryStage);
StackPane dialogLayout = new StackPane();
dialog.setFullScreen(true);
dialog.setResizable(false);
dialog.setFullScreenExitKeyCombination(KeyCombination.NO_MATCH);
Scene dialogScene = new Scene(dialogLayout, 0, 0);
dialogScene.setCursor(Cursor.NONE);
dialogScene.setFill(Color.BLACK);
dialogLayout.setBackground(Background.EMPTY);
dialog.setScene(dialogScene);
dialog.show();
// Auto close the dialog
Platform.runLater(()->{
dialog.close();
primaryStage.setFullScreen(true);
});
});
}
关于java - Raspberry Pi 无法在 JavaFX 应用程序中隐藏鼠标光标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41794346/