On Tue, 7 Apr 2026 16:39:00 GMT, Andy Goryachev <[email protected]> wrote:

>> Christopher Schnick has updated the pull request incrementally with one 
>> additional commit since the last revision:
>> 
>>   Add tests for centering
>
> So the NPE is gone, very good.
> 
> What is not yet clear to me is how it chooses where to show the alert when 
> the parent Stage is not shown.  Arguably, this is not a good state, so I'd 
> expect the alert to show maybe at the center of the screen (which screen, 
> btw, if we have two?)
> 
> So, using this reproducer
> https://github.com/andy-goryachev-oracle/Test/blob/main/src/goryachev/bugs/Alert_NPE_8380926.java
> 
> where the NPE button focuses on a different stage before showing up the 
> alert, I get the following picture (top menu / bottom dock is trimmed).  
> Before clicking on the NPE button, I moved both of the windows from their 
> original positions: 
> 
> <img width="1793" height="1068" alt="Screenshot 2026-04-07 at 09 27 30" 
> src="https://github.com/user-attachments/assets/7119302a-6963-46ae-be8c-37d88f8aae1e";
>  />
> 
> What I see is the alert showing up not at the center of the screen but 
> somewhere closer to the top side of the screen.
> Similarly, if I move both stages to a different screen, the alert still 
> appears on the primary screen.
> 
> Why is that?

@andy-goryachev-oracle 

I think it is the default behaviour. Y is placed on 1/3 of the screen.

>From `Window.java`:


    private static final float CENTER_ON_SCREEN_X_FRACTION = 1.0f / 2;
    private static final float CENTER_ON_SCREEN_Y_FRACTION = 1.0f / 3;

    /**
     * Sets x and y properties on this Window so that it is centered on the
     * current screen.
     * The current screen is determined from the intersection of current window 
bounds and
     * visual bounds of all screens.
     */
    public void centerOnScreen() {
        xExplicit = false;
        yExplicit = false;
        if (peer != null) {
            Rectangle2D bounds = getWindowScreen().getVisualBounds();
            double centerX =
                    bounds.getMinX() + (bounds.getWidth() - getWidth())
                                           * CENTER_ON_SCREEN_X_FRACTION;
            double centerY =
                    bounds.getMinY() + (bounds.getHeight() - getHeight())
                                           * CENTER_ON_SCREEN_Y_FRACTION;

            x.set(centerX);
            y.set(centerY);
            peerBoundsConfigurator.setLocation(centerX, centerY,
                                               CENTER_ON_SCREEN_X_FRACTION,
                                               CENTER_ON_SCREEN_Y_FRACTION);
            applyBounds();
        }
    }


I remember seeing some change about not moving parent window with the modal on 
macos.

-------------

PR Comment: https://git.openjdk.org/jfx/pull/2127#issuecomment-4200874277

Reply via email to