From 82df2ecfa91f5e0c8d7bc651e69e4471dbc329a2 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Tue, 28 Sep 2021 19:34:53 +0200 Subject: [PATCH] ComboBox: paint focus border if combobox component itself is focused (instead of internal text field) or if client property `JComponent.focusOwner` is set Theme Editor: - do not set client property `JComponent.focusOwner` on internal components of combobox and spinner - repaint preview on window activation (necessary because if something changed in editor and switching to another app, the editor is saved and the preview is updated while the editor window is not-active, which hides all focus indicators) --- .../main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java | 3 +++ .../formdev/flatlaf/themeeditor/FlatThemeEditorPane.java | 5 +++++ .../formdev/flatlaf/themeeditor/FlatThemeFileEditor.java | 8 ++++++++ .../formdev/flatlaf/themeeditor/FlatThemePreviewAll.java | 7 +++++-- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java index 1d438c7e..c69365a1 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java @@ -670,6 +670,9 @@ public class FlatComboBoxUI /** @since 1.3 */ public static boolean isPermanentFocusOwner( JComboBox comboBox ) { if( comboBox.isEditable() ) { + if( FlatUIUtils.isPermanentFocusOwner( comboBox ) ) + return true; + Component editorComponent = comboBox.getEditor().getEditorComponent(); return (editorComponent != null) ? FlatUIUtils.isPermanentFocusOwner( editorComponent ) : false; } else diff --git a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeEditorPane.java b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeEditorPane.java index a4b3d4da..e6ee4133 100644 --- a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeEditorPane.java +++ b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeEditorPane.java @@ -166,6 +166,11 @@ class FlatThemeEditorPane scrollPane.getGutter().setLineNumberFont( font ); } + void windowActivated() { + if( preview != null ) + preview.repaint(); + } + @Override public boolean requestFocusInWindow() { return textArea.requestFocusInWindow(); diff --git a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeFileEditor.java b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeFileEditor.java index 1a49c9dc..69a23921 100644 --- a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeFileEditor.java +++ b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeFileEditor.java @@ -148,6 +148,14 @@ class FlatThemeFileEditor restoreState(); restoreWindowBounds(); + addWindowListener( new WindowAdapter() { + @Override + public void windowActivated( WindowEvent e ) { + for( FlatThemeEditorPane themeEditorPane : getThemeEditorPanes() ) + themeEditorPane.windowActivated(); + } + } ); + // load directory if( dir == null ) { String recentDirectory = state.get( KEY_RECENT_DIRECTORY, null ); diff --git a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemePreviewAll.java b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemePreviewAll.java index b9dac102..30eece47 100644 --- a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemePreviewAll.java +++ b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemePreviewAll.java @@ -188,8 +188,11 @@ class FlatThemePreviewAll if( !isControlComponent( comp ) && comp instanceof JComponent ) ((JComponent)comp).putClientProperty( FlatClientProperties.COMPONENT_FOCUS_OWNER, value ); - if( !(comp instanceof Container) || comp instanceof JInternalFrame ) - return; + if( !(comp instanceof Container) || + comp instanceof JComboBox || + comp instanceof JSpinner || + comp instanceof JInternalFrame ) + return; for( Component c : ((Container)comp).getComponents() ) { if( c instanceof JScrollPane )