In the end, I “solved” this by cracking the problem. As Camicre points out, JPopupMenu is pretty buggy. However, this is the only implementation of the Swing popup menu that allows you to have an icon next to each menu item.
My solution was to implement a jpopupmenu listener which, if the user placed the mouse on the menu, after 3 seconds would be set to .isVisible (false) if the user did not put the mouse back on the menu during this time.
To achieve this, I had to use a separate thread that constantly checked if popupmenu was active. If so, check if the mouse was above it using the event listener and set the visibility to false if the user does not enter it again within 3 seconds.
This is not an ideal solution, as the user still needs to wait 3 seconds for the menu to disappear (it should be instantaneous if he / she clicks) and it will disappear even if it is in focus (he should not the user presses the button ) However, he felt "good enough" to accept.
Hope this helps.
Danny king
source share