(Originally posted in JFC/Swing/AWT forum): Can someone please nudge me in the right direction? I can't figure out how the BUTTON_MASK is supposed to work, and the isPopupTrigger() method in the MouseEvent object doesn't appear to register properly in my application. My purpose is to devise a popup help system when a user right-clicks on a component in the GUI. Thanks for your help.
Manfred Leonhardt
Ranch Hand
Joined: Jan 09, 2001
Posts: 1492
posted
0
Hi Scott, Nudge, nudge ...
Regards, Manfred.
Scott Appleton
Ranch Hand
Joined: May 07, 2001
Posts: 195
posted
0
Manfred, thanks for the nudge. However, I can never get the isPopupTrigger() to return true. If I place an else construct after each isPopupTrigger(), the else executes 100% of the time, regardless of which mouse button I press. This behavior is true on both NT and W98. Is there a way to trap for a right mouse button click besides using isPopupTrigger()?
Cindy Glass
"The Hood"
Sheriff
Joined: Sep 29, 2000
Posts: 8521
posted
0
Play with this:
Of course you can get rid of the KeyListener stuff, it was just already in there.
[This message has been edited by Cindy Glass (edited June 07, 2001).]
"JavaRanch, where the deer and the Certified play" - David O'Meara
Scott Appleton
Ranch Hand
Joined: May 07, 2001
Posts: 195
posted
0
Ah, thanks Cindy. The e.getModifiers() is a method I never came across (probably because I wasn't looking in the right place). I haven't tried this code, but it looks like it might do the trick.
Manfred Leonhardt
Ranch Hand
Joined: Jan 09, 2001
Posts: 1492
posted
0
Hi Scott, If you use Cindy's method in your application you should be aware that not all menu popups are registered to the right mouse button. It is usually the case for a right-handed setup mouse but for a left-handed setup mouse it will be backwards (usually left mouse button). That is the reason for isPopupTrigger() method. The popup trigger is usually set in a control panel on Windows (try mouse) ... That might be your problem ... Regards, Manfred.
Scott Appleton
Ranch Hand
Joined: May 07, 2001
Posts: 195
posted
0
Manfred, my popup trigger is set to the right mouse button on my system. But that actually isn't the problem, since no matter which mouse button I click, the isPopupTrigger() is returning false, both at work and at home (so it's probably not a system-specific thing). The BUTTON_MASK modifier at least is being captured properly, so I have something to react to (though I realize that this is prejudicial against left-handed mouse users). Now if only I could figure out how to get the underlying MouseAdapter-enabled panel to intercept the MouseClick event rather than the individual components it contains...