JavaFX application . There is a scene, it is always one, only Root changes. There are many Button , Label , ImageView , MediaView , ScrollPane and so on.

It is necessary for me: that by idleness in the course of n minutes, the necessary layout is established via scene.setRoot() .

    1 answer 1

    As an option, but probably not optimal, because there will be a lot of events; the service can be restarted after its own internal event:

     private class WaitService extends Service { private static final long WAIT_TIME = 10*1000L;//10 sec public long lastChange = System.currentTimeMillis(); @Override protected Task createTask() { return new Task<Void>() { @Override protected Void call() throws Exception { while ( true ) { System.out.println( "check " + ( System.currentTimeMillis() - lastChange ) ); if ( ( System.currentTimeMillis() - lastChange ) > WAIT_TIME ) { return null; } else { try { Thread.currentThread().sleep( 500 ); } catch ( InterruptedException e ) { e.printStackTrace(); return null; } } } } }; } } @Override public void start(Stage stage) throws Exception { ... WaitService service = new WaitService(); EventDispatcher origDispetcher = stage.getEventDispatcher(); mscene.setEventDispatcher( new EventDispatcher() { @Override public Event dispatchEvent( Event event, EventDispatchChain tail ) { if ( service.isRunning() ) { //тут какой-нибудь фильтр System.out.println( "!!" ); service.lastChange = System.currentTimeMillis(); } return origDispetcher.dispatchEvent( event, tail ); } } ); service.setOnSucceeded( e -> { scene.setRoot( new StackPane( new Text( "Hooray" ) ) ); } ); service.restart(); stage.setScene( scene ); stage.show(); } 
    • Thanks for the tip, it came in handy. - Vallaper