diff --git a/CHANGELOG.md b/CHANGELOG.md index 470511f5..74f08aed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ FlatLaf Change Log ================== +## Unreleased + +- Hide focus indicator when window is inactive. + + ## 0.37 - Custom window decorations (Windows 10 only; PR #108; issues #47 and #82) diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatListUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatListUI.java index 34cd9565..d4e7b369 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatListUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatListUI.java @@ -17,6 +17,7 @@ package com.formdev.flatlaf.ui; import java.awt.Color; +import java.awt.EventQueue; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; import javax.swing.JComponent; @@ -106,7 +107,11 @@ public class FlatListUI @Override public void focusLost( FocusEvent e ) { super.focusLost( e ); - toggleSelectionColors(); + + // use invokeLater for the case that the window is deactivated + EventQueue.invokeLater( () -> { + toggleSelectionColors(); + } ); } }; } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTableUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTableUI.java index 6d6b5481..12f0a43a 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTableUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTableUI.java @@ -18,6 +18,7 @@ package com.formdev.flatlaf.ui; import java.awt.Color; import java.awt.Dimension; +import java.awt.EventQueue; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; import javax.swing.JCheckBox; @@ -174,7 +175,11 @@ public class FlatTableUI @Override public void focusLost( FocusEvent e ) { super.focusLost( e ); - toggleSelectionColors(); + + // use invokeLater for the case that the window is deactivated + EventQueue.invokeLater( () -> { + toggleSelectionColors(); + } ); } }; } 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 8e977fba..42ea107f 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 @@ -38,6 +38,7 @@ import java.awt.geom.RoundRectangle2D; import java.util.function.Consumer; import javax.swing.JComponent; import javax.swing.LookAndFeel; +import javax.swing.SwingUtilities; import javax.swing.UIManager; import javax.swing.border.Border; import javax.swing.border.CompoundBorder; @@ -139,8 +140,14 @@ public class FlatUIUtils return c instanceof JComponent && Boolean.TRUE.equals( ((JComponent)c).getClientProperty( "JComboBox.isTableCellEditor" ) ); } + /** + * Returns whether the given component is the permanent focus owner and + * is in the active window. Used to paint focus indicators. + */ public static boolean isPermanentFocusOwner( Component c ) { - return (KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner() == c); + KeyboardFocusManager keyboardFocusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager(); + return keyboardFocusManager.getPermanentFocusOwner() == c && + keyboardFocusManager.getActiveWindow() == SwingUtilities.windowForComponent( c ); } public static boolean isRoundRect( Component c ) {