• 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

Suppress normal mouse click behavior when it is a popup trigger

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi. I am trying to create a GUI in which left and right mouse clicks perform different actions. The left click selects and performs operations and the right click opens a context menu. To be platform independent, I'm using the isPopupTrigger method to determine whether a click is what I would call a "right" click.

My problem is that mouse clicks of any kind are triggering the normal click behavior. I can open my context menu when a mouse event is a popup trigger but then the normal click behavior occurs also.

I can work around the problem by doing the following. I'm using Windows so mouseReleased is the point at which isPopupTrigger will return true.



But I think that if I'm not using Windows, this won't work properly. The mouseClicked method seems like it would be the right place to decide which action to take but at that point, the isPopupTrigger returns false even for right clicks.

Can you suggest a way to do either normal mouse click behavior *or* popup trigger behavior but never do both?

Thanks for your help!
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Peter Desjardins wrote:But I think that if I'm not using Windows, this won't work properly.



What makes you think this? (I haven't written much code which uses mouse listeners, and I haven't run that code on non-Windows systems, but since Java claims to be write-once-run-anywhere, this seems sort of improbable to me.)
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
AFAIK for platform independence you need to test isPopupTrigger in both mousePressed(...) and mouseReleased(...). Not sure whether you require to test in mouseClicked(...) too but it certainly doesn't do any harm to do so.

edit: Just checked this: on Linux, a context menu appears as soon as the right mouse button is pressed, unlike Windows where it appears when the right mouse button is pressed and then released.

Note that this behavior has nothing to do with Java; it's the normal OS behavior.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic