In short, you can do this, but you will need to write your own mouse listener, which may require a lot of copies and folders from the jdk source code, which is not a good idea, and I don’t have to say what license restrictions it will put on your code .
I would start digging out of this method:
javax.swing.plaf.basic.BasicMenuItemUI.Handler#mouseReleased
which seems to be the entry point from where the menu processing engine hides the popup. I would take a closer look
javax.swing.plaf.basic.BasicPopupMenuUI.MouseGrabber#stateChanged
EDIT . Developing @Burhan Valikarimwala's answer, try this apporach: remove all action listeners from the disabled JMenuItem and save them in some static temp structure (say, a Map<WeakReference<JMenuItem>, List<MouseListener>> ), so this will not hide the pop-up window . When you turn on the menu item again, add all the listeners back. Add it to some use method and it will be smooth.
Denis tulskiy
source share