This week's book giveaway is in the Java 9 forum.
We're giving away four copies of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications and have Sander Mak & Paul Bakker on-line!
See this thread for details.
Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Run a Task Just After Scene is Displayed  RSS feed

 
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: 351
21
  • 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: 351
21
  • 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!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!