Evox33 Evox33 - 1 year ago 146
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

setLocationRelativeTo(component)
to do exactly what I need but I did not find anything similar.

Btw. I am using Scala and the official jdk.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download