diff --git a/CHANGELOG.md b/CHANGELOG.md index 0be075e1..bb56843c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ FlatLaf Change Log #718) - TextField: Fixed placeholder text painting, which did not respect horizontal alignment property of `JTextField`. (issue #721) +- Popop: Fixed drop shadow if popup overlaps a heavyweight component. (Windows + 10 only; issue #626) ## 3.2 diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatPopupFactory.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatPopupFactory.java index 46ea8ed5..04b2d16b 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatPopupFactory.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatPopupFactory.java @@ -103,6 +103,10 @@ public class FlatPopupFactory return popup; } + // check whether popup overlaps a heavy weight component + if( !forceHeavyWeight && overlapsHeavyWeightComponent( owner, contents, x, y ) ) + forceHeavyWeight = true; + // create drop shadow popup return new DropShadowPopup( getPopupForScreenOfOwner( owner, contents, x, y, forceHeavyWeight ), owner, contents ); } @@ -389,6 +393,33 @@ public class FlatPopupFactory FlatNativeWindowsLibrary.setWindowCornerPreference( hwnd, FlatNativeWindowsLibrary.DWMWCP_DONOTROUND ); } + private static boolean overlapsHeavyWeightComponent( Component owner, Component contents, int x, int y ) { + Window window = SwingUtilities.getWindowAncestor( owner ); + if( window == null ) + return false; + + Rectangle r = new Rectangle( new Point( x, y ), contents.getPreferredSize() ); + return overlapsHeavyWeightComponent( window, r ); + } + + private static boolean overlapsHeavyWeightComponent( Component parent, Rectangle r ) { + if( !parent.isVisible() || !r.intersects( parent.getBounds() ) ) + return false; + + if( !parent.isLightweight() && !(parent instanceof Window) ) + return true; + + if( parent instanceof Container ) { + Rectangle r2 = new Rectangle( r.x - parent.getX(), r.y - parent.getY(), r.width, r.height ); + for( Component c : ((Container)parent).getComponents() ) { + if( overlapsHeavyWeightComponent( c, r2 ) ) + return true; + } + } + + return false; + } + //---- class NonFlashingPopup --------------------------------------------- private static class NonFlashingPopup