I’m seeing a really strange issue with JPopupMenu’s and JComboBox’s. When the application is under heavy load, there are times when our popup menus appear with the right size and position, but just as blank, grey boxes.
The other issue we think is related is that sometimes, we see stanards JComboBox’s appear as though they have no items in them (i.e., they don’t pull down). We’ve seen this issue when the application is not under load. They’re not making database calls, or anything like that to populate the combo box items – they use hard-coded items.
I’ve put the popup menu creation in a SwingUtils.invokelater call, and that helped, but did not make the problem completely go away. I don’t know what I would do to change the combo box’s behavior. If we just right-click again, the context menu will reappear – fully populated. To get the combo boxes working right again, we just close the dialog that contains them, and then just open it back up.
We’re using Java 1.6.17 in a standard desktop app. Is there a bug I don’t know about, or something else that would solve it, or at least help us know what else might be going on?
All GUI components should be constructed “on the event dispatch thread,” and access to any data owned by another thread must be correctly synchronized. There’s a nice summary under Memory Consistency Properties.
Addendum: @Boro raises two compelling points related to this problem.
The intermittent nature of the problem only suggests incorrect synchronization, but proof to the contrary is difficult. The affected system is likely too large to correct by inspection; sadly, an sscce would be contrived and obviously incorrect.
One common scenario is a
ListModelthat is constructed lazily, perhaps on another thread. One approach is to log theEventQueueand look for anomalies, as suggested here.