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ß" <[email protected]>
An: openjfx-dev <[email protected]>
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

Reply via email to