我是TornadoFX的新手,我不知道如何设置PrimaryStage或场景属性,如场景高度、宽度或PrimaryStage模态. 请帮帮我.

使现代化

I want to set Scene height and width, Look at this example:

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并配置主stage的尺寸,这将再次决定场景的尺寸:

override fun start(stage: Stage) {
    super.start(stage)
    stage.width = 800.0
    stage.height = 600.0
}

To make this even simpler, there will be a function in TornadoFX 1.5.3 that let you create the Scene for the primary view yourself:

override fun createPrimaryScene(view: UIComponent) = Scene(view.root, 800.0, 600.0)

最终结果将是相同的,因此您只需保留第一个示例中的代码即可.

Kotlin相关问答推荐

Kotlin—从列表中枚举属性计算不同值的数量

如果启用了Flyway迁移,则不能具有配置属性';datources.default.架构-生成

Kotlin多平台(KMP)保存到文件不能在iOS上保存

Scala与Kotlin中的迭代

使函数同时挂起和取消挂起

如何使用 Kotlin Maven 更改 Minecraft 插件中的 Shulker GUI 标题

如何使用 Mockk 模拟返回值类的 Kotlin 函数类型?

如何在 Compose 中创建可重用的修饰符?

在 APK META-INF/library_release.kotlin_module 中复制的重复文件

未为任务启用 Gradle 构建缓存

如何修复 ViewPager2 中的Design assumption violated错误?

Kotlin boxed Int 不一样

如何用 kotlin 打包 List

Kotlin:找不到符号类片段或其他 android 类

如何使用mockk库模拟android上下文

我应该使用Kotlin数据类作为JPA实体吗?

uses-sdk:minSdkVersion 16 不能小于库中声明的版本 23

Kotlin Flow 收集后无法执行代码

在 Android 12 (SDK 31) 中获取 android.app.ForegroundServiceStartNotAllowedException

如何在 kotlin 中创建重复对象数组?