Reputation: 1900
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?
I have this part of code
scene.setCursor(Cursor.NONE);
But i do not know how to link it to idle time.
Upvotes: 1
Views: 628
Reputation: 209553
You can do something like this:
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);
});
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
.
Upvotes: 4