kotlinfxmltornadofx

Tornadofx: update a label text (FXML) during an runAsync task


I am working on a simple UI using TornadoFX and FXML (without TornadoFx's DSL).
There is only one big button who call a function with a runasync inside and it's all working.

But... How can I bind, eg, a label text to track TaskStatus(), eg, title?

MyApp.kt

class MainView : View() {

    private val taskStatus = TaskStatus()

    private val lblStatus: Label by fxid()

    override val root : VBox by fxml("/views/main.fxml")


    
    init {
        
        lblStatus.bind(taskStatus.title) // ----> dummy's attempt: don't work

    }



    private fun check( host: String?, port: Int ) {

       runAsync(taskStatus) {

           updateTitle("Connecting...")

           // Make something...

           updateTitle("Checking system...")

           // Make something...

           updateTitle("Reading...")

           // Make something...
           
           updateTitle("Closing...")
         
       }

    }

}

Solution

  • Stupid mistake...

    Need this:

    lblStatus.textProperty().bind( taskStatus.title )
    

    Instead of this:

    lblStatus.bind(taskStatus.title)