Is there any possibility to show a (spinning, not stuck) progress indicator while theres some heavy lifting done in javafx ui thread?
Backstory: Ive got to load a rather big tableView into a TitledPane (which takes multiple seconds). The command that makes the whole thing lag is TitledPane.setContent(myTableView). So i want to at least show some loading animation or indicator during this time.
So right now im doing the following, to give the ui thread enough room to breath to show my loading animation before doing the expensive call:
showMyLoadingAnimation();
PauseTransition pause = new PauseTransition(Duration.seconds(1));
pause.setOnFinished(event -> {
setContent(myTableView);
});
pause.play();
dismissMyLoadingAnimation();
this works get the progress indicator shown, but once the ui thread starts working on setContent its getting stuck.
ive seen some people using swing to display a layover or dialog with the animation just to have it running in a different thread and not get stuck, but couldnt find a convincing solution yet.
EDIT: Ok, i found that root of the problem. so ive got tables prefHeightProperty bound to the size of the list its displaying as shown here: JavaFX - Adapt TableView height to number of rows did that weeks ago, worked, forgot about it.
that costs a LOT of time. so although timing the call when setting the binding doesnt show that it takes a lot of time, the ui thread seems have a massive problem with it when the tables are getting big.
thanks to james, his answer will be the correct one for most people running into this kind of issue.
can someone please comment this issue over there: JavaFX - Adapt TableView height to number of rows (since this is first question i dont have enough rep. yet to comment)