Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Layout loop caused by FlatTitlePane #420

Closed
ingokegel opened this issue Nov 10, 2021 · 4 comments
Closed

Layout loop caused by FlatTitlePane #420

ingokegel opened this issue Nov 10, 2021 · 4 comments
Milestone

Comments

@ingokegel
Copy link
Contributor

I'm hitting a layout loop that is triggered by FlatTitlePane::menuBarLayouted calling revalidate() thereby somehow triggering a layout on the JRootPane. I'm not sure how this can happen, but I see this deterministically in some places in my automated UI tests that use AssertJ Swing as a framework. The async stack trace chain in IntelliJ looks like this:

2021-11-10_14-40-12

and continues like that until IntelliJ truncates it. When this layout loop is triggered for the first time, it continues until the frame is closed. I notice this because the testing framework will become extremely slow in this case. The custom repaint manager in the stack trace is just for me to set a breakpoint, it also happens without it.

Passing the VM parameter -Dflatlaf.useWindowDecorations prevents this problem, but this is obviously not desirable.

My workaround is to set

UIManager.put("RootPaneUI", CustomFlatRootPaneUI.class.getName());

with

public static class CustomFlatRootPaneUI extends FlatRootPaneUI {
    @SuppressWarnings("unused")
    public static ComponentUI createUI(JComponent c ) {
        return new CustomFlatRootPaneUI();
    }

    @Override
    protected FlatTitlePane createTitlePane() {
        return new FlatTitlePane(rootPane) {
            @Override
            protected void menuBarLayouted() {
                updateNativeTitleBarHeightAndHitTestSpotsLater();
            }
        };
    }
}

which effectively just removes the revalidate() call from FlatTitlePane::menuBarLayouted. I don't see any negative effects from that removal.

@DevCharly
Copy link
Collaborator

Thanks for reporting/debugging this issue.
Have not seen this before, but invoking revalidate() from layout() was obviously a bad idea...

I've added the call to revalidate() in commit 30c7b44

It was necessary to update the layout when adding components to the menu bar.

With test app FlatWindowDecorationsTest it is possible to test it. When selecting the "right aligned stretching component" checkbox, a glue component and a progress bar are added to the menubar/title bar.

Before:

image

With revalidate() the title label is moved:

image

Without revalidate() the title label is missing:

image

Anyway, need to find a solution without revalidate()...

@DevCharly
Copy link
Collaborator

Replacing revalidate() with doLayout() works for me and should also fix the layout loop.

Could you please add doLayout() to your CustomFlatRootPaneUI ... menuBarLayouted() method and check whether the layout loop is gone?

@ingokegel
Copy link
Contributor Author

Just checked with one of my UI tests where the layout loop was always reproducible and calling doLayout() instead of revalidate() does not trigger the layout loop.

DevCharly added a commit that referenced this issue Nov 11, 2021
@DevCharly
Copy link
Collaborator

Fixed in 1.6.2. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants