• Post Reply Bookmark Topic Watch Topic
  • New Topic

Suppress normal mouse click behavior when it is a popup trigger

 
Peter Desjardins
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • 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!
 
Paul Clapham
Sheriff
Posts: 21892
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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.)
 
Darryl Burke
Bartender
Posts: 5155
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!