According to the ScalaFX API, the dialog.onShown tasks run directly AFTER the dialog is shown.
I have some task that takes time. I need to open a "LOADING" dialog for the user to see while the task runs. This is an illustration of my code:
val dialog = new Dialog() {
title = "LOADING"
onShown = handle {
myTask()
}
}.showAndWait()
Of course my dialog has other content as well, which are irrelevant. The problem is when I run the program, the TASK is run first and then the dialog shows after it. I tried creating a new stage instead of dialog and faced the same problem. Tried inserting some println
statements before the task to check, and indeed the printing was happening before the dialog shows. I also tried to let the program sleep for 5 seconds using Thread.sleep(5000)
to give the dialog time to show (maybe it is freezing), with no luck at all.