fixed missing focus indicators in heavy-weight popups (issue #273)

This commit is contained in:
Karl Tauber
2021-03-24 11:43:06 +01:00
parent e18a04f9e6
commit de6e5bd800
2 changed files with 11 additions and 3 deletions

View File

@@ -18,6 +18,7 @@ FlatLaf Change Log
(issue #275) (issue #275)
- Custom window decorations: Fixed right aligned progress bar in embedded menu - Custom window decorations: Fixed right aligned progress bar in embedded menu
bar was overlapping window title. (issue #272) 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 - InternalFrame: Fixed translucent internal frame menu bar background if
`TitlePane.unifiedBackground` is `true`. (issue #274) `TitlePane.unifiedBackground` is `true`. (issue #274)

View File

@@ -185,7 +185,8 @@ public class FlatUIUtils
/** /**
* Returns whether the given component is the permanent focus owner and * 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" ) @SuppressWarnings( "unchecked" )
public static boolean isPermanentFocusOwner( Component c ) { public static boolean isPermanentFocusOwner( Component c ) {
@@ -195,12 +196,18 @@ public class FlatUIUtils
Object value = ((JComponent)c).getClientProperty( FlatClientProperties.COMPONENT_FOCUS_OWNER ); Object value = ((JComponent)c).getClientProperty( FlatClientProperties.COMPONENT_FOCUS_OWNER );
if( value instanceof Predicate ) { if( value instanceof Predicate ) {
return ((Predicate<JComponent>)value).test( (JComponent) c ) && return ((Predicate<JComponent>)value).test( (JComponent) c ) &&
keyboardFocusManager.getActiveWindow() == SwingUtilities.windowForComponent( c ); isInActiveWindow( c, keyboardFocusManager.getActiveWindow() );
} }
} }
return keyboardFocusManager.getPermanentFocusOwner() == c && 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);
} }
/** /**