aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JButton behaviour for JPopupMenu Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JButton behaviour for JPopupMenu" Watch "JButton behaviour for JPopupMenu" New topic
Author

JButton behaviour for JPopupMenu

Faisal Ul-Haque
Greenhorn

Joined: Dec 02, 2011
Posts: 10
Hi All,
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.

My test class is:
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4530
    
    5

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.


luck, db
There are no new questions, but there may be new answers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JButton behaviour for JPopupMenu