Easier placement of stages with positioning anchor
Andy Goryachev
andy.goryachev at oracle.com
Wed Nov 26 19:32:15 UTC 2025
+1 for Dialog and centerOnScreen (or make it as another option in AnchorPoint or ClampPolicy?)
-andy
From: openjfx-dev <openjfx-dev-retn at openjdk.org> on behalf of Marius Hanl <mariushanl at web.de>
Date: Wednesday, November 26, 2025 at 05:37
To: michaelstrau2 at gmail.com <michaelstrau2 at gmail.com>, openjfx-dev at openjdk.org <openjfx-dev at openjdk.org>
Subject: Re: Easier placement of stages with positioning anchor
I like this idea. Especially since there is not much control right now.
For reference, what I normally do to make sure that a Dialog can not exceed the bounds is:
dialog.setOnShown(_ -> Platform.runLater(() -> resizeRelocateDialogIfBoundsExceedsScreen(dialog)));
Which is a bit hacky, and I need to do the calculation by myself. Example of a part of that method:
private static void relocateDialog(Dialog<?> dialog, Rectangle2D screenBounds) {
// If the dialog exceeds the screen to the right
if (dialog.getX() + dialog.getWidth() > screenBounds.getMaxX()) {
dialog.setX(screenBounds.getMaxX() - dialog.getWidth() - SCREEN_EDGE_SPACING);
}
if (dialog.getY() + dialog.getHeight() > screenBounds.getMaxY()) {
dialog.setY(screenBounds.getMaxY() - dialog.getHeight() - SCREEN_EDGE_SPACING);
}
// If the dialog exceeds the screen to the left
if (dialog.getX() < screenBounds.getMinX()) {
dialog.setX(screenBounds.getMinX() + SCREEN_EDGE_SPACING);
}
if (dialog.getY() < screenBounds.getMinY()) {
dialog.setY(screenBounds.getMinY() + SCREEN_EDGE_SPACING);
}
}
Since a Dialog uses a Stage, your Anchor API could also be used there (and in the future, integrated into Dialog, which is delegating to the showAndWait(..) method of the Stage)?
That would be helpful, and a usecase I often had.
I also wonder if we want to retrofit that into the centerOnScreen() method (in the future?).
So that this method will use (set) the underlying Anchor System now instead. So we have only one way to position a Stage.
-- Marius
Gesendet: Dienstag, 25. November 2025 um 20:04
Von: "Michael Strauß" <michaelstrau2 at gmail.com>
An: openjfx-dev <openjfx-dev at openjdk.org>
Betreff: Easier placement of stages with positioning anchor
I've prepared a small enhancement for Stage that allows applications
to show a stage relative to a reference point, similar to how popups
work. This is a useful addition for a potential system tray support
(where windows are often placed relative to a system tray icon), but
also comes in handy for multi-window applications.
Comments are welcome.
PR: https://github.com/openjdk/jfx/pull/1986
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/openjfx-dev/attachments/20251126/8d90f2fe/attachment-0001.htm>
More information about the openjfx-dev
mailing list