diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ca656e2..cd4be405 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ FlatLaf Change Log - Tree and List: Fixed painting of rounded drop backgrounds. (issue #1023) - Popup: Showing tooltip in inactive window brought that window to front (made it active) and potentially hid the previously active window. (issue #1037) +- Popup: No longer reuse popup windows for menus to avoid immediately closing + dialogs on ChromeOS. (issue #1029) - macOS: Fixed window "flashing" when switching from a light to a dark theme (or vice versa). Especially when using animated theme changer (see [FlatLaf Extras](flatlaf-extras)). diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatSystemProperties.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatSystemProperties.java index d84ee855..5e46f27c 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatSystemProperties.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatSystemProperties.java @@ -16,6 +16,7 @@ package com.formdev.flatlaf; +import javax.swing.JPopupMenu; import javax.swing.SwingUtilities; import com.formdev.flatlaf.util.UIScale; @@ -147,6 +148,25 @@ public interface FlatSystemProperties */ String USE_ROUNDED_POPUP_BORDER = "flatlaf.useRoundedPopupBorder"; + /** + * Species whether popup windows may be reused without (temporary) hiding them. + * E.g. if "moving" a tooltip to follow the mouse pointer, normally it is necessary + * to hide the tooltip and show it again at the new location, which causes some + * flicker with heavy-weight popup windows that FlatLaf uses on all platforms. + *

+ * If {@code true}, hiding popup window is deferred for an event cycle, + * which allows reusing still visible popup window and avoids flicker when "moving" the popup. + *

+ * Note that {@link JPopupMenu} popup windows (menus and combobox lists) are newer reused. + *

+ * Allowed Values {@code false} and {@code true}
+ * Default {@code true} + * + * @since 3.7 + */ + String REUSE_VISIBLE_POPUP_WINDOW = "flatlaf.reuseVisiblePopupWindow"; + + /** * Specifies whether vertical text position is corrected when UI is scaled on HiDPI screens. *

diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatPopupFactory.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatPopupFactory.java index 885f91eb..bc265567 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatPopupFactory.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatPopupFactory.java @@ -676,8 +676,11 @@ public class FlatPopupFactory return; disposed = true; - // immediately hide non-heavy weight popups or combobox popups - if( !(popupWindow instanceof JWindow) || contents instanceof BasicComboPopup ) { + // immediately hide non-heavy weight popups, popup menus and combobox popups + // of if system property is false + if( !(popupWindow instanceof JWindow) || contents instanceof JPopupMenu || + !FlatSystemProperties.getBoolean( FlatSystemProperties.REUSE_VISIBLE_POPUP_WINDOW, true ) ) + { hideImpl(); return; }