From 7c9f550d4cf2fc7c78f2eebe3eda67d96b3751b3 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Tue, 14 Sep 2021 14:16:53 +0200 Subject: [PATCH] ComboBox: fixed popup location if shown above of combo box (Java 8 only) --- CHANGELOG.md | 1 + .../com/formdev/flatlaf/ui/FlatComboBoxUI.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 07ae2a8f..44682445 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ FlatLaf Change Log `StringBuilder`, `StringBuffer`, or any other object that returns HTML text in method `toString()`. (similar to issue #12) - ComboBox: Fixed popup border painting on HiDPI screens (e.g. at 150% scaling). +- ComboBox: Fixed popup location if shown above of combo box (Java 8 only). - ComboBox (editable): Fixed wrong border of internal text field under special circumstances. - Spinner: Fixed painting of border corners on left side. (issue #382; 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 9517405b..392efd52 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 @@ -730,6 +730,21 @@ public class FlatComboBoxUI return height; } + @Override + public void show( Component invoker, int x, int y ) { + // Java 8: fix y coordinate if popup is shown above the combobox + // (already fixed in Java 9+ https://bugs.openjdk.java.net/browse/JDK-7072653) + if( y < 0 && !SystemInfo.isJava_9_orLater ) { + Border popupBorder = getBorder(); + if( popupBorder != null ) { + Insets insets = popupBorder.getBorderInsets( this ); + y -= insets.top + insets.bottom; + } + } + + super.show( invoker, x, y ); + } + @Override protected void paintChildren( Graphics g ) { super.paintChildren( g );