Java Mouse Event Right Click
Asked Answered
S

3

93

On my three button mouse MouseEvent.BUTTON2= Middle Click and MouseEvent.BUTTON3 = Right Click.

Is this the case on a two button mouse?

Thanks

Sanctify answered 24/12, 2010 at 10:29 Comment(0)
D
186

To avoid any ambiguity, use the utilities methods from SwingUtilities :

SwingUtilities.isLeftMouseButton(MouseEvent anEvent) SwingUtilities.isRightMouseButton(MouseEvent anEvent) SwingUtilities.isMiddleMouseButton(MouseEvent anEvent)

Dogmatic answered 24/12, 2010 at 10:40 Comment(0)
K
10

Yes, take a look at this thread which talks about the differences between platforms.

How to detect right-click event for Mac OS

BUTTON3 is the same across all platforms, being equal to the right mouse button. BUTTON2 is simply ignored if the middle button does not exist.

Kielty answered 24/12, 2010 at 10:37 Comment(0)
G
1

I've seen

anEvent.isPopupTrigger() 

be used before. I'm fairly new to Java so I'm happy to hear thoughts about this approach :)

Glazunov answered 29/6, 2013 at 2:0 Comment(1)
yes, but according to bugs.java.com/bugdatabase/view_bug.do?bug_id=4119064 and my own practice this function won't work correctly in Windows. And the bug lasts for 16 years already...Fluctuation

© 2022 - 2024 — McMap. All rights reserved.