mojtab23 mojtab23 - 4 months ago 29
Java Question

Way of setting PrimaryStage or Scene properties in TornadoFX

I am new to tornadoFX and I don't know how to setup PrimaryStage or Scene properties like Scene height or width or PrimaryStage modality.
Please help me.

UPDATE

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"))
}
}

Answer

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: View) = 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.