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.