I would like to ask if anybody has an explanation and solution for the following problem.
I have a JPopupMenu activated by a JButton and it is exhibiting the following functionality:
1. When the JPopupMenu is not visible and the JButton is clicked --> shows JPopupMenu (AS EXPECTED)
2. When the JButton is clicked after the JPopupMenu is made visible and discarded by clicking anywhere else --> shows JPopupMenu (AS EXPECTED)
3. When the JButton is clicked after the JPopupMenu is made visible --> flickers (hides and shows) the JPopupMenu (NOT DESIRED FUNCTIONALY)
My frustration is scenario 3 and if anyone has an explanation and solution it would be appreciated.
In the button's actionPerformed, it's pointless to test whether the popup menu is visible, as the action of clicking the button hides the popup. This happens before the button is released and the actionListener code executes.
You might like to disable the button and re-enable it when the popup is hidden.
Edit: No, that's not a solution. The button becomes enabled because a moue down over the disabled button hides the popup.
Edit2: Queuing the enabling of the button solves the problem. Code updated.
A better approach might be to use a JToggleButton.
There are no new questions, but there may be new answers.