Java Mouse Event Right Click

JavaSwingMouseRight ClickSwingutilities

Java Problem Overview


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

Is this the case on a two button mouse?

Thanks

Java Solutions


Solution 1 - Java

To avoid any ambiguity, use the utilities methods from http://download.oracle.com/javase/6/docs/api/javax/swing/SwingUtilities.html#isLeftMouseButton(java.awt.event.MouseEvent)">SwingUtilities</a> :

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

Solution 2 - Java

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

https://stackoverflow.com/questions/2972512/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.

Solution 3 - Java

I've seen

anEvent.isPopupTrigger() 

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDD.View Question on Stackoverflow
Solution 1 - JavabarjakView Answer on Stackoverflow
Solution 2 - JavaCodemwnciView Answer on Stackoverflow
Solution 3 - JavaSam JarmanView Answer on Stackoverflow