日安。我想知道是否有一种方便或简化的方法来将FXTask的messageProperty和runningProperty绑定到Label的textProperty和visibleWhen属性,而无需耦合FXTask和Label本身?
例如,在下面的示例应用程序中,我通过将label的引用耦合到一个任务来绑定messageProperty,这引入了一个额外的lateinit var statusLabel。类似地,我通过将任务的引用耦合到引入额外val task的标签来绑定runningProperty。
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)https://stackoverflow.com/questions/51428584
复制相似问题