The issue was successfully reproduced on:
- JDK 7u12 b06 (latest)
- JDK 7u4 b11 (the first JDK 7 from Oracle)
- JDK 8 b69
This issue happens, because of concurrency between internal processing of calls to JComboBox.hidePopup() and JComboBox.showPopup() methods. A deep research showed the following facts:
1. Processing of "sun.awt.UngrabEvent" cancels JPopupMenu of JComboBox, what is the reason of this bug.
2. A call to JComboBox.hidePopup() generates "sun.awt.UngrabEvent", which is processed asynchronously, in its underlying code (the method "public void stateChanged(ChangeEvent e)" of javax.swing.plaf.basic.BasicPopupMenuUI.MouseGrabber) in JDK 7, JDK 8 on OS X.
3. Behavior from point #2 does not happen neither on Windows OS, nor on Linux OS, because of a particular implementation of "ungrab(Window w)" method of "sun.awt.SunToolkit" for OS X.
A pseudo code which describes a process leading to this bug is presented below.
1. JComboBox.hidePopup() - (the popup menu becomes hidden)
"sun.awt.UngrabEvent" is posted to AWT event queue.
2. JComboBox.showPopup() - (the popup menu becomes shown)
3. "sun.awt.UngrabEvent" is dispatched to JFrame - (the popup menu becomes hidden again)
Any shown popup is closed.
One of possible solutions could be not posting of "sun.awt.UngrabEvent" by "sun.lwawt.LWWindowPeer.ungrab()", when it is called from "sun.lwawt.LWToolkit". A similar strategy is applied in native code of JDK for Windows OS.