• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Run a Task Just After Scene is Displayed

 
Logan Snow
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I need to run a background task that starts just after my scene is displayed, and I need it to be able to update the UI. Is there any way to do this? Thanks
 
John Damien Smith
Ranch Hand
Posts: 296
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"The javafx.concurrent package, takes care of multithreaded code that interacts with the UI and ensures that this interaction happens on the correct thread."

You can also use Platform.runLater(), but usually a Task or Service suffices. Platform.runLater() can also be used in conjunction with a Task if necessary - there are examples in the Task javadoc.
 
Logan Snow
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alright, I have tried using a task, but I do not know where to start it. It seems when I start it in the initialise() method of the controller, when the scene is actually displayed the task stops. Any ideas?
 
John Damien Smith
Ranch Hand
Posts: 296
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Show your code.
 
Logan Snow
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh wait never mind it works thanks so much for your help!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic