Menus: fixed IllegalComponentStateException: component must be showing on the screen to determine its location when submenu is empty (PR #490; issue #247)

This commit is contained in:
Karl Tauber
2022-03-14 00:23:53 +01:00
parent 53bde84710
commit 2ae9bb381d

View File

@@ -130,8 +130,14 @@ debug*/
mouseX = mouseLocation.x; mouseX = mouseLocation.x;
mouseY = mouseLocation.y; 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]; JPopupMenu popup = (JPopupMenu) path[subMenuIndex];
if( !popup.isShowing() ) {
uninstallEventQueue();
return;
}
// get invoker screen bounds
Component invoker = popup.getInvoker(); Component invoker = popup.getInvoker();
invokerBounds = (invoker != null) invokerBounds = (invoker != null)
? new Rectangle( invoker.getLocationOnScreen(), invoker.getSize() ) ? new Rectangle( invoker.getLocationOnScreen(), invoker.getSize() )