我是 tornadoFX 的新手,我不知道如何设置 PrimaryStage 或 Scene 属性,例如 Scene 高度或宽度或 PrimaryStage 模态。 请帮我。
更新
我要设置场景的高度和宽度,看这个例子:
dependencies {
compile 'no.tornado:tornadofx:1.5.2'
compile "org.jetbrains.kotlin:kotlin-stdlib:1.0.3"
}
import javafx.scene.control.Label
import javafx.scene.layout.VBox
import tornadofx.App
import tornadofx.FX
import tornadofx.View
class Main : App() {
override val primaryView = MyView::class
init {
// this two lines have error ( Val cannot be reassigned. )
FX.primaryStage.scene.height = 600.0
FX.primaryStage.scene.width = 800.0
// or this line causes this exception ( java.lang.NoSuchMethodException )
FX.primaryStage.isResizable = false
}
}
class MyView : View() {
override val root = VBox()
init {
root.children.add(Label("My label"))
}
}
最佳答案
如果您不想让主视图决定初始场景大小,您可以覆盖 App.start
并配置主舞台的尺寸,这将再次决定场景的尺寸场景:
override fun start(stage: Stage) {
super.start(stage)
stage.width = 800.0
stage.height = 600.0
}
为了使这更简单,TornadoFX 1.5.3 中将有一个函数让您自己为主视图创建场景:
override fun createPrimaryScene(view: UIComponent) = Scene(view.root, 800.0, 600.0)
最终结果将是相同的,因此您可以保留第一个示例中的代码。
关于java - TornadoFX 中设置 PrimaryStage 或 Scene 属性的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38543474/