How to set PrimaryStage or Scene properties in TornadoFX

I am new to tornadoFX and I don’t know how to set up PrimaryStage or Scene properties such as scene height or width or the PrimaryStage mod. Please help me.

UPDATE

I want to set the height and width of the scene, 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"))
   }
}
+4
source share
2 answers

If you do not want the main view to determine the initial size of the scene, you can override App.startand adjust the dimensions of the main stage, which will again determine the size of the scene:

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

To make it even simpler, in TornadoFX 1.5.3 there will be a function that allows you to independently create a scene for the main view:

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

, .

+7

TornadoFX Guide. TornadoFX.

, . , ( TornadoFX):

class Main : App() {
    override val primaryView = MyView::class
}

class MyView : View() {
    override val root = VBox()

    init {
        with (root) {
            prefWidth = 800.0
            prefHeight = 600.0
            label("My label")
        }
    }
}

:

class Main : App() {
    override val primaryView = MyView::class

    init {
        importStylesheet(Style::class)
    }
}

class MyView : View() {
    override val root = VBox()

    init {
        with (root) {
            label("My label")
        }
    }
}

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

- ( prefHeight = 10.cm prefWidth = 5.inches). , CSS, , ( ) .

: TornadoFX.

+1

Source: https://habr.com/ru/post/1648873/


All Articles