From 5388353e63a220202a2717a5a09a8dbb69f65fa9 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Sat, 25 Nov 2023 18:12:13 +0100 Subject: [PATCH] fixed broken rendering after resizing window to minimum size and then increasing size again (issue #767) --- CHANGELOG.md | 2 ++ .../formdev/flatlaf/ui/FlatRootPaneUI.java | 2 +- .../formdev/flatlaf/ui/FlatTabbedPaneUI.java | 31 +++++++++++++++++-- .../com/formdev/flatlaf/ui/FlatTitlePane.java | 4 +++ 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99d635f53..fe889b127 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ FlatLaf Change Log and #750) - OptionPane: Fixed styling custom panel background in `JOptionPane`. (issue #761) +- Fixed broken rendering after resizing window to minimum size and then + increasing size again. (issue #767) ## 3.2.5 diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRootPaneUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRootPaneUI.java index 861251013..3dde8f151 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRootPaneUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRootPaneUI.java @@ -499,7 +499,7 @@ public void layoutContainer( Container parent ) { @Override public void invalidateLayout( Container parent ) { if( titlePane != null ) - titlePane.menuBarChanged(); + titlePane.menuBarInvalidate(); } @Override diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTabbedPaneUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTabbedPaneUI.java index f235fcf1b..6078cfb4c 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTabbedPaneUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTabbedPaneUI.java @@ -276,6 +276,7 @@ public class FlatTabbedPaneUI private boolean blockRollover; private boolean rolloverTabClose; private boolean pressedTabClose; + private boolean inBasicLayoutContainer; private Object[] oldRenderingHints; private Map oldStyleValues; @@ -2044,7 +2045,7 @@ private TabCloseButton() { //---- class ContainerUIResource ------------------------------------------ - private static class ContainerUIResource + private class ContainerUIResource extends JPanel implements UIResource { @@ -2052,6 +2053,20 @@ private ContainerUIResource( Component c ) { super( new BorderLayout() ); add( c ); } + + @SuppressWarnings( "deprecation" ) + @Override + public void reshape( int x, int y, int w, int h ) { + // Avoid that leading/trailing tab area components are temporary moved/resized + // to content area bounds (done in BasicTabbedPaneUI.TabbedPaneLayout.layoutContainer() + // and in BasicTabbedPaneUI.TabbedPaneScrollLayout.layoutContainer()) + // and subsequently moved/resized to its final bounds within the tab area. + // This avoids an unnecessary repaint (and maybe re-layout) of the content area. + if( inBasicLayoutContainer ) + return; + + super.reshape( x, y, w, h ); + } } //---- class FlatTabAreaButton -------------------------------------------- @@ -3009,7 +3024,12 @@ protected Dimension calculateTabAreaSize() { @Override public void layoutContainer( Container parent ) { - super.layoutContainer( parent ); + inBasicLayoutContainer = true; + try { + super.layoutContainer( parent ); + } finally { + inBasicLayoutContainer = false; + } Rectangle bounds = tabPane.getBounds(); Insets insets = tabPane.getInsets(); @@ -3214,7 +3234,12 @@ public void layoutContainer( Container parent ) { // runWithOriginalLayoutManager() is necessary for correct locations // of tab components layed out in TabbedPaneLayout.layoutTabComponents() runWithOriginalLayoutManager( () -> { - delegate.layoutContainer( parent ); + inBasicLayoutContainer = true; + try { + delegate.layoutContainer( parent ); + } finally { + inBasicLayoutContainer = false; + } } ); int tabsPopupPolicy = getTabsPopupPolicy(); diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTitlePane.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTitlePane.java index 3de0e068d..6eb29660a 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTitlePane.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTitlePane.java @@ -608,6 +608,10 @@ protected void menuBarLayouted() { doLayout(); } + void menuBarInvalidate() { + menuBarPlaceholder.invalidate(); + } + @Override public void paint( Graphics g ) { super.paint( g );