<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif"><div class="gmail_default">Hi Martin,</div><div class="gmail_default"><br></div><div class="gmail_default">Just to say thanks for looking into it and the following explanation, it's good to know. There's some quirks to be aware of for sure.</div><div class="gmail_default"><br></div><div class="gmail_default"><br></div><div class="gmail_default">Kind Regards,</div><div class="gmail_default">Cormac</div></div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Mon, 7 Jul 2025 at 15:50, Martin Fox <<a href="mailto:martinfox656@gmail.com">martinfox656@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>Cormac,<div><br></div><div>When you call Dialog.show everything happens in the order you expect. When you call Dialog.showAndWait the order of operations changes. For one, the Dialog code issues the DIALOG_SHOWN event *before* showing the window (it wants to send out that event before an internal call to Window.showAndWait blocks). For two, when Window.sizeToScene is called on a window that’s not yet visible it gets deferred. The end result is that with Dialog.showAndWait your onShown handler gets called before the window is sized to the scene but when you use Dialog.show your onShown handler is called after.</div><div><br></div><div>I don’t think any of this is documented. I've run into the deferred sizeToScene behavior before. I didn’t dig much but it looks like it was added over a decade ago in response to some bug reports. The timing of Dialog.setOnShown is also old behavior. There’s a comment in the Dialog.java about this:</div><div><br></div><div><blockquote type="cite"><div> // this is slightly odd - we fire the SHOWN event before the show()</div><div> // call, so that users get the event before the dialog blocks</div></blockquote><br></div><div>So I can see what’s going on in case #2. Due to the re-ordering the sizeToScene logic is happening after the window’s minimum size is set. The docs don’t say what should happen if the scene’s desired size is less than the window’s minimum. What you’re getting is a scene that doesn’t fill the window. One work-around for case 2 is to call setOnShown on the dialog’s window instead of the dialog itself.</div><div><div><br></div><div>BTW, I think what you’re seeing in case #3 is correct and not a bug. You’re altering the size of the scene after the window has been sized and shown. I wouldn’t expect the window to automatically re-size to match the new scene dimensions. I think the expectation is that you would alter the scene’s dimensions in onShowing instead of onShown.</div><div><br></div><div>Martin</div><div><br></div><div><blockquote type="cite"><div>On Jul 3, 2025, at 2:24 PM, Cormac Redmond <<a href="mailto:credmond@certak.com" target="_blank">credmond@certak.com</a>> wrote:</div><br><div><div dir="ltr"><div style="font-family:verdana,sans-serif">Hi,</div><div style="font-family:verdana,sans-serif"><br></div><div style="font-family:verdana,sans-serif">I have noticed inconsistent and confusing size/layout behaviour with Dialogs when changing min width or height (after shown).</div><div style="font-family:verdana,sans-serif"><br></div><div style="font-family:verdana,sans-serif">The behaviour depends on whether changing min width/height on the Stage, or the DialogPane itself, and whether show() or showAndWait() is used.</div><div style="font-family:verdana,sans-serif"><br></div><div style="font-family:verdana,sans-serif">In summary:</div><div style="font-family:verdana,sans-serif"><ol><li>Set Stage mins + show()</li><ul><li>no bug</li></ul><li> Set Stage mins + showAndWait()</li><ul><li>improper layout: background applies only to label (i.e., size before re-size), button wrong position, re-sizing window fixes the problem</li></ul><li>3 Set DialogPane mins + show()</li><ul><li>min sizes are ignored, button is visible, until it comes into focus, and then the button disappears, you can find it if you resize window close to the mins set</li></ul><li>4 Set DialogPane mins + showAndWait()</li><ul><li>no bug</li></ul></ol></div><div style="font-family:verdana,sans-serif">It's happening in JFX23/24/25. Note, these may seem trivial/fixable, or you may ask "why would you do that?", but there are reasons I won't clutter the mail with.</div><div style="font-family:verdana,sans-serif"><br></div><div style="font-family:verdana,sans-serif">Anyway, it's best presented with a set of examples and code.</div><div style="font-family:verdana,sans-serif"><br></div><div style="font-family:verdana,sans-serif">Re points 1 and 2 above, exact same code, except red is showAndWait() and green is show():</div><div style="font-family:verdana,sans-serif"><br></div><div style="font-family:verdana,sans-serif"><span id="m_3537963254473814898cid:ii_mcnvsu5r0"><image.png></span></div><div style="font-family:verdana,sans-serif"><br></div><div style="font-family:verdana,sans-serif">Obviously, they should behave the same. Then slightly resize the red one:</div><div style="font-family:verdana,sans-serif"><br></div><div style="font-family:verdana,sans-serif"><span id="m_3537963254473814898cid:ii_mcnvv3h31"><image.png></span></div><div style="font-family:verdana,sans-serif"><br></div><div style="font-family:verdana,sans-serif"><br></div><div style="font-family:verdana,sans-serif">Examples 3 and 4 above -- again, same code. Purple is show(), yellow is showAndWait().</div><div style="font-family:verdana,sans-serif"><br></div><div style="font-family:verdana,sans-serif"><span id="m_3537963254473814898cid:ii_mcnvw1912"><image.png></span></div><div style="font-family:verdana,sans-serif"><br></div><div style="font-family:verdana,sans-serif">After you close the yellow dialog:</div><div style="font-family:verdana,sans-serif"><br></div><span id="m_3537963254473814898cid:ii_mcnw1blv4"><image.png></span><br><div style="font-family:verdana,sans-serif"><br></div><div style="font-family:verdana,sans-serif">They should be the same size from the outset.</div><div style="font-family:verdana,sans-serif"><br></div><div style="font-family:verdana,sans-serif"><br></div><div style="font-family:verdana,sans-serif"><br></div><div style="font-family:verdana,sans-serif">public class DialogBug extends Dialog<Boolean> {<br><br>    public DialogBug(final String s, boolean flip) {<br>        setTitle("Bug");<br>        setResizable(true);<br><br>        final DialogPane dp = getDialogPane();<br>        dp.setStyle(s);<br>        dp.getButtonTypes().add(ButtonType.CLOSE);<br>        dp.setContent(new Label("Content"));<br><br>        // Setting stage size causes the bug<br>        setOnShown(e -> {<br><br>            if (flip) {<br>                // Set stage sizes<br>                Stage st = (Stage) dp.getScene().getWindow();<br>                st.setMinHeight(260);<br>                st.setMinWidth(360);<br>            } else {<br>                // Set dialog sizes: note buttons disappear when you resize<br>                dp.setMinHeight(260);<br>                dp.setMinWidth(360);<br>            }<br>        });<br>    }<br><br>    public static class BugApp extends Application {<br>        @Override<br>        public void start(final Stage st) throws Exception {<br><br>            final boolean FLIP_ME = true; // make true for other bug<br><br>            if (FLIP_ME) {<br>                // Note: bug doesn't happen when using show() only. Stage is fully green on show.<br>                new DialogBug("-fx-background-color: green;", true).show(); // NO BUG<br><br>                // showAndWait presents the bug; background not fully drawn, button shifts on re-size<br>                new DialogBug("-fx-background-color: red;", true).showAndWait(); // BUG<br>            } else {<br>                // A different type of issue: two different sizes and button behaviour<br>                // Notice:<br>                // - same dialogs, different sizes<br>                // - how button in purple dialog shifts when yellow dialog pane is closed<br>                new DialogBug("-fx-background-color: purple;", false).show(); // BUG<br>                <br>                new DialogBug("-fx-background-color: yellow;", false).showAndWait(); // NO BUG<br>            }<br>        }<br>    }<br>}</div><div style="font-family:verdana,sans-serif"><br></div><div style="font-family:verdana,sans-serif">Thoughts?</div><div style="font-family:verdana,sans-serif"><br></div><div style="font-family:verdana,sans-serif"><br></div><div style="font-family:verdana,sans-serif"><br></div><div style="font-family:verdana,sans-serif">Kind Regards,</div><div style="font-family:verdana,sans-serif">Cormac</div></div>
</div></blockquote></div><br></div></div></blockquote></div></div>