private void menuSelectionChanged() {
		MenuElement[] path = MenuSelectionManager.defaultManager().getSelectedPath();

/*debug
		System.out.println( "--- " + path.length );
		for( int i = 0; i < path.length; i++ )
			System.out.println( "   " + i + ": " + path[i].getClass().getName() );
debug*/

		// find submenu in menu selection
		int subMenuIndex = findSubMenu( path );

		// uninstall if there is no submenu in selection
		if( subMenuIndex < 0 || subMenuIndex != path.length - 1 ) {
			uninstallEventQueue();
			return;
		}

		// get current mouse location
		PointerInfo pointerInfo = MouseInfo.getPointerInfo();
		Point mouseLocation = (pointerInfo != null) ? pointerInfo.getLocation() : new Point();
		mouseX = mouseLocation.x;
		mouseY = mouseLocation.y;

		// 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 && invoker.isShowing())
			? new Rectangle( invoker.getLocationOnScreen(), invoker.getSize() )
			: null;

		// check whether mouse location is within invoker
		if( invokerBounds != null && !invokerBounds.contains( mouseX, mouseY ) ) {
			uninstallEventQueue();
			return;
		}

		// compute top/bottom target locations
		Point popupLocation = popup.getLocationOnScreen();
		Dimension popupSize = popup.getSize();
		targetX = (mouseX < popupLocation.x + (popupSize.width / 2))
			? popupLocation.x
			: popupLocation.x + popupSize.width;
		targetTopY = popupLocation.y;
		targetBottomY = popupLocation.y + popupSize.height;

		// install own event queue to suppress mouse events when mouse is moved within safe triangle
		if( subMenuEventQueue == null ) {
			SubMenuEventQueue queue = new SubMenuEventQueue();

			try {
				Toolkit toolkit = Toolkit.getDefaultToolkit();
				toolkit.getSystemEventQueue().push( queue );

				// check whether push() worked
				// (e.g. SWTSwing uses own event queue that does not support push())
				if( toolkit.getSystemEventQueue() != queue ) {
					eventQueuePushNotSupported = true;
					LoggingFacade.INSTANCE.logSevere( "FlatLaf: Failed to push submenu event queue. Disabling submenu safe triangle.", null );
					return;
				}

				subMenuEventQueue = queue;
			} catch( RuntimeException ex ) {
				// catch runtime exception from EventQueue.push()
				eventQueuePushNotSupported = true;
				LoggingFacade.INSTANCE.logSevere( "FlatLaf: Failed to push submenu event queue. Disabling submenu safe triangle.", ex );
				return;
			}
		}

		// create safe triangle painter
		if( safeTrianglePainter == null && UIManager.getBoolean( KEY_SHOW_SAFE_TRIANGLE ) )
			safeTrianglePainter = new SafeTrianglePainter( popup );
	}
Improves usability of submenus by using a
<a href="https://height.app/blog/guide-to-build-context-menus#safe-triangle">safe triangle</a>
to avoid that the submenu closes while the user moves the mouse to it.

@author Karl Tauber
flatlaf-core/src/main/java/com/formdev/flatlaf/SubMenuUsabilityHelper.java