Inconsistent drawing/layouts of Dialogs & show()/showAndWait() differences

Cormac Redmond credmond at certak.com
Thu Jul 3 21:24:12 UTC 2025


Hi,

I have noticed inconsistent and confusing size/layout behaviour with
Dialogs when changing min width or height (after shown).

The behaviour depends on whether changing min width/height on the Stage, or
the DialogPane itself, and whether show() or showAndWait() is used.

In summary:

   1. Set Stage mins + show()
      - no bug
   2.  Set Stage mins + showAndWait()
      - improper layout: background applies only to label (i.e., size
      before re-size), button wrong position, re-sizing window fixes the problem
   3. 3 Set DialogPane mins + show()
      - 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
   4. 4 Set DialogPane mins + showAndWait()
      - no bug

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.

Anyway, it's best presented with a set of examples and code.

Re points 1 and 2 above, exact same code, except red is showAndWait() and
green is show():

[image: image.png]

Obviously, they should behave the same. Then slightly resize the red one:

[image: image.png]


Examples 3 and 4 above -- again, same code. Purple is show(), yellow is
showAndWait().

[image: image.png]

After you close the yellow dialog:

[image: image.png]

They should be the same size from the outset.



public class DialogBug extends Dialog<Boolean> {

    public DialogBug(final String s, boolean flip) {
        setTitle("Bug");
        setResizable(true);

        final DialogPane dp = getDialogPane();
        dp.setStyle(s);
        dp.getButtonTypes().add(ButtonType.CLOSE);
        dp.setContent(new Label("Content"));

        // Setting stage size causes the bug
        setOnShown(e -> {

            if (flip) {
                // Set stage sizes
                Stage st = (Stage) dp.getScene().getWindow();
                st.setMinHeight(260);
                st.setMinWidth(360);
            } else {
                // Set dialog sizes: note buttons disappear when you resize
                dp.setMinHeight(260);
                dp.setMinWidth(360);
            }
        });
    }

    public static class BugApp extends Application {
        @Override
        public void start(final Stage st) throws Exception {

            final boolean FLIP_ME = true; // make true for other bug

            if (FLIP_ME) {
                // Note: bug doesn't happen when using show() only. Stage
is fully green on show.
                new DialogBug("-fx-background-color: green;", true).show();
// NO BUG

                // showAndWait presents the bug; background not fully
drawn, button shifts on re-size
                new DialogBug("-fx-background-color: red;",
true).showAndWait(); // BUG
            } else {
                // A different type of issue: two different sizes and
button behaviour
                // Notice:
                // - same dialogs, different sizes
                // - how button in purple dialog shifts when yellow dialog
pane is closed
                new DialogBug("-fx-background-color: purple;",
false).show(); // BUG

                new DialogBug("-fx-background-color: yellow;",
false).showAndWait(); // NO BUG
            }
        }
    }
}

Thoughts?



Kind Regards,
Cormac
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/openjfx-dev/attachments/20250703/a0b73404/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 12215 bytes
Desc: not available
URL: <https://mail.openjdk.org/pipermail/openjfx-dev/attachments/20250703/a0b73404/image-0004.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 8224 bytes
Desc: not available
URL: <https://mail.openjdk.org/pipermail/openjfx-dev/attachments/20250703/a0b73404/image-0005.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 12750 bytes
Desc: not available
URL: <https://mail.openjdk.org/pipermail/openjfx-dev/attachments/20250703/a0b73404/image-0006.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 2688 bytes
Desc: not available
URL: <https://mail.openjdk.org/pipermail/openjfx-dev/attachments/20250703/a0b73404/image-0007.png>


More information about the openjfx-dev mailing list