diff --git a/CHANGELOG.md b/CHANGELOG.md index 10420b8f..3703f269 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ FlatLaf Change Log (issue #275) - Custom window decorations: Fixed right aligned progress bar in embedded menu bar was overlapping window title. (issue #272) +- Fixed missing focus indicators in heavy-weight popups. (issue #273) - InternalFrame: Fixed translucent internal frame menu bar background if `TitlePane.unifiedBackground` is `true`. (issue #274) diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatUIUtils.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatUIUtils.java index 59ae3446..f9476443 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatUIUtils.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatUIUtils.java @@ -185,7 +185,8 @@ public class FlatUIUtils /** * Returns whether the given component is the permanent focus owner and - * is in the active window. Used to paint focus indicators. + * is in the active window or in a popup window owned by the active window. + * Used to paint focus indicators. */ @SuppressWarnings( "unchecked" ) public static boolean isPermanentFocusOwner( Component c ) { @@ -195,12 +196,18 @@ public class FlatUIUtils Object value = ((JComponent)c).getClientProperty( FlatClientProperties.COMPONENT_FOCUS_OWNER ); if( value instanceof Predicate ) { return ((Predicate)value).test( (JComponent) c ) && - keyboardFocusManager.getActiveWindow() == SwingUtilities.windowForComponent( c ); + isInActiveWindow( c, keyboardFocusManager.getActiveWindow() ); } } return keyboardFocusManager.getPermanentFocusOwner() == c && - keyboardFocusManager.getActiveWindow() == SwingUtilities.windowForComponent( c ); + isInActiveWindow( c, keyboardFocusManager.getActiveWindow() ); + } + + private static boolean isInActiveWindow( Component c, Window activeWindow ) { + Window window = SwingUtilities.windowForComponent( c ); + return window == activeWindow || + (window != null && window.getType() == Window.Type.POPUP && window.getOwner() == activeWindow); } /**