JavaFX在空闲时设置鼠标隐藏 [英] JavaFX set mouse hidden when idle

查看:271
本文介绍了JavaFX在空闲时设置鼠标隐藏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在JavaFX应用程序上隐藏鼠标,当用户空闲时,让我们说1秒钟?当鼠标移动时再显示一次?

How can i hide the mouse on JavaFX application, when the user is idle, lets say for 1 sec ? and show it again when the mouse move?

我有这部分代码

scene.setCursor(Cursor.NONE);

但我不知道如何将其链接到空闲时间。

But i do not know how to link it to idle time.

推荐答案

你可以这样做:

PauseTransition idle = new PauseTransition(Duration.seconds(1));
idle.setOnFinished(e -> scene.setCursor(Cursor.NONE));
scene.addEventHandler(Event.ANY, e -> {
    idle.playFromStart();
    scene.setCursor(Cursor.DEFAULT);
});

这会产生一秒的暂停。当用户执行任何操作时,将重新启动暂停并将光标设置为默认值。如果暂停结束,只有在整个持续时间内没有重新启动时才会发生(即如果用户一秒钟没有做任何事情),则光标设置为 NONE

This creates a one-second pause. When the user performs any action, the pause is restarted and the cursor set to the default. If the pause finishes, which can only happen if it wasn't restarted for the whole duration (i.e. if the user did nothing for a second), then the cursor is set to NONE.

这篇关于JavaFX在空闲时设置鼠标隐藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆