Way of setting PrimaryStage or Scene properties in TornadoFX

You should definitely check out the TornadoFX Guide. It's a great resource for getting started in TornadoFX.

To answer your question, you can set the size in the view's root. This should do what you want (usning TornadoFX's builder pattern):

class Main : App(MyView::class)

class MyView : View() {
    override val root = vbox {
        prefWidth = 800.0
        prefHeight = 600.0

        label("My label")
    }
}

Another option is to use type safe stylesheets:

class Main : App(MyView::class, Style::class)

class MyView : View() {
    override val root = vbox {
        label("My label")
    }
}

class Style : Stylesheet() {
    init {
        root {
            prefHeight = 600.px
            prefWidth = 800.px
        }
    }
}

The advantage of the type safe stylesheet is you can use different units (you could set just as easily say prefHeight = 10.cm or prefWidth = 5.inches). It can basically do anything CSS can do, but is much more convenient, powerful, and (as the name suggests) type safe.

Disclaimer: I was involved in designing and building the type safe stylesheet system for TornadoFX.


If you don't want to let the primary view dictate the initial scene size, you can override App.start and configure the dimensions of the primary stage, which again will dictate the dimensions of the scene:

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)

The end result will be the same, so you can just keep the code in the first example though.