首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将`FXTask`消息绑定到TornadoFX中无组件耦合的`Label`

将`FXTask`消息绑定到TornadoFX中无组件耦合的`Label`
EN

Stack Overflow用户
提问于 2018-07-20 01:22:14
回答 0查看 84关注 0票数 0

日安。我想知道是否有一种方便或简化的方法来将FXTaskmessagePropertyrunningProperty绑定到LabeltextPropertyvisibleWhen属性,而无需耦合FXTaskLabel本身?

例如,在下面的示例应用程序中,我通过将label的引用耦合到一个任务来绑定messageProperty,这引入了一个额外的lateinit var statusLabel。类似地,我通过将任务的引用耦合到引入额外val task的标签来绑定runningProperty

代码语言:javascript
复制
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)
EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51428584

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档