为什么当我使用进度指示器对象调用视图时,onDock事件不会第一次运行?

时间:2019-01-18 12:05:43

标签: javafx kotlin tornadofx

当我调用使用进度指示器或进度条的视图时,onDock事件不会第一次触发,但是接下来的几次我会调用窗口。我创建了一个小程序对其进行测试。我不知道我是否正确调用了该视图,但是使用我使用的其余控件,这种情况不会发生。

MainView:

package com.example.demo.view

import javafx.geometry.Pos
import tornadofx.*
import javafx.stage.Modality
import javafx.stage.StageStyle

class MainView : View("Hello TornadoFX") {

    override val root = hbox {
        alignment = Pos.CENTER
        button("Show indicator") {
            minWidth = 200.0
            this.paddingAll = 5
            action {
                find(Test::class).openWindow(StageStyle.UTILITY,
                        Modality.APPLICATION_MODAL, true, null, true)
            }
        }
    }
}

测试:

package com.example.demo.view

import javafx.scene.control.ProgressIndicator
import kotlinx.coroutines.*
import tornadofx.*

class Test : View("My View") {

    private var indicatorProgress: ProgressIndicator by singleAssign()

    override val root = hbox {
        indicatorProgress = progressindicator {
            prefWidth = 100.0
            prefHeight = 100.0
            progress = 0.0
            GlobalScope.launch(Dispatchers.IO) {
                while (true) {
                    for (i in 1..10) {
                        progress = i.toDouble() / 10.0
                        delay(1000)
                    }
                }
            }
        }
    }

    override fun onDock() {
        super.onDock()

        println("Entering view...")
    }

    override fun onUndock() {
        super.onUndock()

        println("Leaving view...")
    }
}

结果:

12:58:33: Executing task 'run'...

:wrapper

BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed
:discoverMainScriptsExtensions
:compileKotlin UP-TO-DATE
:compileJava NO-SOURCE
:processResources NO-SOURCE
:classes UP-TO-DATE
:run
Leaving view...
Entering view...
Leaving view...
Entering view...
Leaving view...

BUILD SUCCESSFUL in 18s
3 actionable tasks: 2 executed, 1 up-to-date
12:58:51: Task execution finished 'run'.

:run之后应首先出现“正在进入视图...”,但不会执行onDock事件。

我打错窗户了吗?

非常感谢大家。

0 个答案:

没有答案