0

I have a TableView whose data is refreshed when the user clicks a button. However, the database query used to get the data can take some time.

During the search, I wish to display the TableView's placeholder (which is a ProgressIndicator:

// Add progress indicator while searching
ProgressIndicator pi = new ProgressIndicator(ProgressIndicator.INDETERMINATE_PROGRESS);
pi.setMaxHeight(tblCallRecordList.getHeight() / 2);
tblCallRecordList.setPlaceholder(pi);

// Clear the table data
searchResults.clear();
tblCallRecordList.setItems(searchResults);

// Run the new search
processSearch();

However, when running the program, the TableView is never changed and the processSearch() method runs right away, keeping the old data in the TableView until the search is completed.

If I comment out processSearch(), the placeholder is displayed just fine.

Is there some strange thread flow going on that I am missing?

Zephyr
  • 9,885
  • 4
  • 28
  • 63
  • You're running this on the FX Application Thread. So that thread will not be able to perform any of it's other responsibilities (repainting the UI, responding to user input, etc) until your `processSearch()` method finishes. – James_D Aug 29 '17 at 19:44
  • I am confused as to why it does not even process the code directly above the `processSearch()` call, though. Is the parent method processed in full before the UI can be updated as well? – Zephyr Aug 29 '17 at 20:14
  • It does process it. All you do is change some properties in some objects. The visual result of those changes won't appear in your UI until the FX Application Thread gets a chance to repaint the UI, which it can't do because you are making it busy getting stuff from your database (something the UI thread has no business doing at all). – James_D Aug 29 '17 at 20:19

0 Answers0