Good day. I was wondering if there is a convenient or streamlined way of binding FXTask
's messageProperty
and runningProperty
to Label
's textProperty
and visibleWhen
property accordingly without coupling FXTask
and Label
themselves?
For example in the sample app below, I'm binding messageProperty
by coupling label's reference to a task, which introduces an extra lateinit var statusLabel
. Similarly, I'm binding runningProperty
by coupling task's reference to a label which introduces an extra val task
.
class DummyView : View("Dummy View") {
override val root = vbox {
lateinit var statusLabel: Label
val task = object : Task<Void>() {
public override fun call(): Void? {
Platform.runLater { statusLabel.textProperty().bind(messageProperty()) } // label coupling
updateMessage("Initializing task...")
(1..3).forEach {
Thread.sleep(1000)
updateMessage("Doing task: $it...")
}
Thread.sleep(1000)
updateMessage("Task done")
Thread.sleep(1000)
return null
}
}
button("Do task") {
action {
Thread(task).apply {// task coupling
isDaemon = true
}.start()
}
}
statusLabel = label("Status") {
visibleWhen(task.runningProperty()) // task coupling
}
}
}
class DummyApp : App(DummyView::class)
See Question&Answers more detail:os