Evox33 Evox33 - 7 months ago 36
Java Question

JavaFX Dialog location relativ to window (Canvas) position

I was wondering if there is a (simple) way to place a JavaFX Dialog relative to another GUI-Component.

I have two monitors and the dialog always open in the center of the primary monitor. I know Swing had a method

to do exactly what I need but I did not find anything similar.

Btw. I am using Scala and the official jdk.


Given a node that is part of an active scene graph (i.e. displayed on the screen),

Bounds bounds = node.localToScreen(node.getBoundsInLocal());

will give the bounds of the node in screen coordinates. You can then call getMinX(), getMaxX(), getWidth(), getMinY(), getMaxY(), and getHeight() is needed to position your dialog as required.