Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Mouse Event Right Click

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

Is this the case on a two button mouse?

Thanks

like image 527
DD. Avatar asked Dec 24 '10 10:12

DD.


People also ask

How do you right click in Java?

BUTTON2 = Middle Click and MouseEvent. BUTTON3 = Right Click.

What is mouse event in Java?

public class MouseEvent extends InputEvent. An event which indicates that a mouse action occurred in a component. A mouse action is considered to occur in a particular component if and only if the mouse cursor is over the unobscured part of the component's bounds when the action happens.

Which method is used to process mouse click public void?

Methods of MouseListener interfacepublic abstract void mouseClicked(MouseEvent e); public abstract void mouseEntered(MouseEvent e); public abstract void mouseExited(MouseEvent e); public abstract void mousePressed(MouseEvent e);


2 Answers

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

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

like image 195
barjak Avatar answered Sep 20 '22 17:09

barjak


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.

like image 45
Codemwnci Avatar answered Sep 21 '22 17:09

Codemwnci