diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatClientProperties.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatClientProperties.java index 17d16c40..d03e5ae2 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatClientProperties.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatClientProperties.java @@ -172,6 +172,25 @@ public interface FlatClientProperties */ String OUTLINE_WARNING = "warning"; + /** + * Specifies a callback that is invoked to check whether a component is permanent focus owner. + * Used to paint focus indicators. + *
+ * May be useful in special cases for custom components. + *
+ * Use a {@link java.util.function.Predicate} that receives the component as parameter: + *
{@code
+ * myComponent.putClientProperty( "JComponent.focusOwner",
+ * (Predicate) c -> {
+ * return ...; // check here
+ * } );
+ * }
+ *
+ * Component {@link javax.swing.JComponent}
+ * Value type {@link java.util.function.Predicate<javax.swing.JComponent>
+ */
+ String COMPONENT_FOCUS_OWNER = "JComponent.focusOwner";
+
//---- Popup --------------------------------------------------------------
/**
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 58693238..1f49eb93 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
@@ -39,6 +39,7 @@ import java.awt.geom.Rectangle2D;
import java.awt.geom.RoundRectangle2D;
import java.util.IdentityHashMap;
import java.util.WeakHashMap;
+import java.util.function.Predicate;
import java.util.function.Supplier;
import javax.swing.JComponent;
import javax.swing.JTable;
@@ -175,8 +176,18 @@ public class FlatUIUtils
* Returns whether the given component is the permanent focus owner and
* is in the active window. Used to paint focus indicators.
*/
+ @SuppressWarnings( "unchecked" )
public static boolean isPermanentFocusOwner( Component c ) {
KeyboardFocusManager keyboardFocusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
+
+ if( c instanceof JComponent ) {
+ Object value = ((JComponent)c).getClientProperty( FlatClientProperties.COMPONENT_FOCUS_OWNER );
+ if( value instanceof Predicate ) {
+ return ((Predicate