Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

App hangs when adding new tab - how to make concurrent?

 
Ranch Hand
Posts: 146
2
Mac Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have put together a relatively small app which calculates some properties of a graph to help me learn JavaFX. The GUI opens a new tab for each graph created. Since some of the calculations can be quite long running (e.g. with a large number of nodes specified), I want to show the new tab and have the properties display "Calculating..." until they have been computed, at which point they should then show the result. However, what actually happens is that the app hangs until all the calculations have been completed.

Each of the calculations is computed using a Task:



When creating the view, the individual tasks are specified, e.g.:



With the result of the Task as a Worker bound to the textProperty() of the relevant TextField:



Once the View has been added to a new Tab and shown, I execute the tasks:





For what it's worth, full source code is available on GitHub.

What am I doing incorrectly that causes the app to hang until the tab has finished calculating all the values?
 
Sheriff
Posts: 7113
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you're going to have to do something along these lines:

...but of course it can't numNodesField, it will have to be something that knows what TextField to update by task.  
 
Ashley Bye
Ranch Hand
Posts: 146
2
Mac Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, thanks. I'll take a look and see what I come up with.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic