Reputation: 597
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
Upvotes: 2
Views: 1015
Reputation: 45456
Different issues have been reported for Linux and JavaFX 11, and some of them share the same root cause: the change from GTK 2 to GTK 3.
This answer already explains it in detail.
As for the Windows issue, it has been already filed here, and it has been fixed, so probably you could try JavaFX 13-ea+11 to test it.
In the meantime, or if you have to stick to a released JavaFX 11/12 version, the only workaround is the one suggested in the mentioned answer: run the app with GTK 2, that can be set with the system property:
java -Djdk.gtk.version=2
Upvotes: 4