gpt4 book ai didi

kotlin - 在Kotlin/TornadoFX中关闭 View 后如何执行清理操作?

转载 作者:行者123 更新时间:2023-12-02 13:20:30 24 4
gpt4 key购买 nike

我一直在搜索文档和IDE自动完成建议,但无法解决。我找到的最接近的是onDelete(),它不能按照我的设想工作。

我只需要一种在关闭 View 时运行一些清理代码的方法。

使用文档中的简单示例,这是一次失败的尝试。

import tornadofx.*

class MyApp: App(MyView::class)

class MyView: View() {
// this does not print when the window is closed
override fun onDelete() {
super.onDelete()
println("Print on close!")
}
override val root = vbox {
button("Press me")
label("Waiting")
}
}

fun main(args: Array<String>) {
launch<MyApp>(args)
}

根据以下建议,另一个尝试失败:
import tornadofx.*

class MyApp: App(MyView::class)

class MyView: View() {
// "Closing" is never printed when closing this view"
override fun onDock() {
currentWindow?.onHidingProperty()?.onChangeOnce {
println("Closing")
}
}
override val root = vbox {
button("Press me")
label("Waiting")
}
}

fun main(args: Array<String>) {
launch<MyApp>(args)
}

最佳答案

我现在在我的项目中使用它。 setOnCloseRequest是我的选择!

override fun onDock() {
currentWindow?.setOnCloseRequest {
println("Closing")
}
}

关于kotlin - 在Kotlin/TornadoFX中关闭 View 后如何执行清理操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57503184/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com