• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Capturing right-click from mouse in AWT

 
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(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.
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Scott,
Nudge, nudge ...

Regards,
Manfred.
 
Scott Appleton
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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()?
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
Scott Appleton
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic