Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is it RightClick ?

 
Manikandan Adaikkalavan
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
how to detect whether itz Mouse's RightClick or LeftClick with the help of mouse event ??
I need to find out the right click ?

Thanks in advance,
Manikandan
 
Manikandan Adaikkalavan
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i got it.
Answer is
if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0)
System.out.println("RIGHT CLICK");
else System.out.println("LEFT CLICK");
 
Matt Senecal
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This should work:
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps the documentation on MouseEvent will give you an idea...
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah yes, the old three-fer response... and you answered your own question in one of the responses - not bad, not bad.
Here's an example another strategy you could use:
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that your example code would consider a click from the middle mouse button (if it exists) as a click from the left mouse button.
 
Manikandan Adaikkalavan
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
whether the following condition fails
if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0)
{}
......
if there is a middle button in MOUSE ?
 
Manikandan Adaikkalavan
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried this example...but giving compilation error
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
another solution i used to do myself was to use the methods: isMetaDown() and isControlDown()
if one of them returns true (the first i think) the the right button is pressed if the second returns true the middle button is pressed.
(could be the other way around , just check it).
this , in my opinion is a pretty good solution even before jdk 1.4 (before the getButton() method) because it works on macintoshes who only have 1 button mouse. so pressing control while pressing the one button emulates right button like it should.
 
Manikandan Adaikkalavan
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Sorry .....I totally got confused...
i need to have a check for rightclick whether the mouse has one button or two buttons or three buttons ...
whether the following code works fine for all cases ???
if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0)
{
// Itz Right Click
}

I have two buttons in my Mouse and this works great....for other two ....i don't know....
Will somebody please help me out ???

Thanks,
Manikandan
 
Manikandan Adaikkalavan
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i got another solution....
There are three methods in
javax.swing.SwingUtilities class
public static boolean isLeftMouseButton(MouseEvent anEvent)
public static boolean isRightMouseButton(MouseEvent anEvent)
public static boolean isMiddleMouseButton(MouseEvent anEvent)
which can be used to find out which button is clicked!

- Manikandan
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well done!
i was looking for those!
couldnt remember where i saw them.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic