Click to See Complete Forum and Search --> : How to get mouse right-click


Valerie Bradley
August 18th, 1999, 02:26 PM
I apologize if this question has been answered already, if so please point me to the article.

Anyway, I need to implement context-sensitive right-click popup menus. You know, like what you get if you right-click on a file name within the Windows Explorer. These popup menus will be used mainly by right-clicking the nodes of a JTree.

Anyway, I have not yet been able to find a solution that works. I would appreciate any pointers that anyone can give me.

Thanks!!

- Valerie
Software Engineer
Intel Corporation

* All opinions are mine and not those of my employer.

August 19th, 1999, 12:17 AM
Get the MouseEvent object. There is method called isPopupTrigger() which says that the event is the pop-up trigger event for the platform.

Or use this.
if((me.getModifiers() & MouseEvent.BUTTON1_MASK)==0 ){
//Right click occured.
}
where "me" is the mouseEvent object. This works for only mouse that have 2 buttons.

regards,
arun...

Kiran
August 19th, 1999, 12:43 AM
hai,
Try this...
In the mouse click event, use the 'isMetaDown'
function of the MouseEvent object. It returns true
if the mouse was clicked. However I don't think it will work for APPLETS.
Eg.
xxxx(MouseEvent e)
{
if(e.isMetaDown())
-----your code
}

This should work, else I'am sorry.
Bye.

August 19th, 1999, 09:20 AM
If u add a mouseListener for a component and say override mouseClicked method ,then in this method use this for right mouse button click
if (event.getModifiers() == 4) and add neccessary code in the if block(e

August 19th, 1999, 09:31 AM
actually,

try MouseEvent.isPopupTrigger() in:
public void mouseClicked(MouseEvent e)
{
if (e.isPopupTrigger())
{
// show popup
}
}

Valerie Bradley
August 19th, 1999, 10:36 AM
Thanks for all the suggestions! I'll try them out today and I'll let you know how it goes. :)

Thanks again! I really appreciate your help.

- Valerie
Software Engineer
Intel Corporation

* All opinions are mine and not those of my employer.