I'm developing a program in JavaFX (more specifically FornadoFX because I write it in Kotlin). What I've noticed is that when main window opens it initially in top left corner and then it jumps to the center.
This is how I start the application: launch<MainWindowClass>(args)
And this is my start
method:
override fun start(stage: Stage) {
with(stage){
minWidth = 600.0
minHeight = 250.0
//Making it appear in the center
val screenBounds = Screen.getPrimary().visualBounds
x = screenBounds.width / 2 - minWidth / 2
y = screenBounds.height / 2 - minHeight / 2
scene = Scene(Group(), minWidth, minHeight)
super.start(this)
}
}
Central part (lines from val screenBounds...
to scene = ...
) have been based on this answer.
However no matter if they are or not there the window always opens in top left and then jumps to set position, rather then being first shown there in the first place.
EDIT:
This is the minimal working example of the bug:
import javafx.scene.Group
import javafx.scene.Scene
import javafx.stage.Screen
import javafx.stage.Stage
import tornadofx.*
class MainWindow: App(MainView::class) {
class MainView: View() {
override val root = label("A window")
}
companion object {
@JvmStatic fun main(args: Array<String>){
launch<MainWindow>(args)
}
}
override fun start(stage: Stage) {
with(stage){
minWidth = 600.0
minHeight = 250.0
val screenBounds = Screen.getPrimary().visualBounds
x = screenBounds.width / 2 - minWidth / 2
y = screenBounds.height / 2 - minHeight / 2
scene = Scene(Group(), minWidth, minHeight)
super.start(this)
}
}
}
Also some info about system: Java version: 11 Operating system: Ubuntu 18.04 LTS