From 2ae9bb381dbec9508bd4bbebfe223425ce5f7119 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Mon, 14 Mar 2022 00:23:53 +0100 Subject: [PATCH] Menus: fixed `IllegalComponentStateException: component must be showing on the screen to determine its location` when submenu is empty (PR #490; issue #247) --- .../java/com/formdev/flatlaf/SubMenuUsabilityHelper.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/SubMenuUsabilityHelper.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/SubMenuUsabilityHelper.java index 19958f4f..157e8a94 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/SubMenuUsabilityHelper.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/SubMenuUsabilityHelper.java @@ -130,8 +130,14 @@ debug*/ mouseX = mouseLocation.x; mouseY = mouseLocation.y; - // get invoker screen bounds + // check whether popup is showing, which is e.g. not the case if it is empty JPopupMenu popup = (JPopupMenu) path[subMenuIndex]; + if( !popup.isShowing() ) { + uninstallEventQueue(); + return; + } + + // get invoker screen bounds Component invoker = popup.getInvoker(); invokerBounds = (invoker != null) ? new Rectangle( invoker.getLocationOnScreen(), invoker.getSize() )