Skip to content

Commit

Permalink
fixed missing focus indicators in heavy-weight popups (issue #273)
Browse files Browse the repository at this point in the history
  • Loading branch information
DevCharly committed Mar 24, 2021
1 parent e18a04f commit de6e5bd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
13 changes: 10 additions & 3 deletions flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatUIUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ public static boolean isCellEditor( Component c ) {

/**
* 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 ) {
Expand All @@ -195,12 +196,18 @@ public static boolean isPermanentFocusOwner( Component c ) {
Object value = ((JComponent)c).getClientProperty( FlatClientProperties.COMPONENT_FOCUS_OWNER );
if( value instanceof Predicate ) {
return ((Predicate<JComponent>)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);
}

/**
Expand Down

0 comments on commit de6e5bd

Please sign in to comment.