简体   繁体   中英

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...")
         
       }

    }

}

Stupid mistake...

Need this:

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

Instead of this:

lblStatus.bind(taskStatus.title) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM