How to get mouse right-click
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.
Re: How to get mouse right-click
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...
Re: How to get mouse right-click
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.
Re: How to get mouse right-click
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
Re: How to get mouse right-click
actually,
try MouseEvent.isPopupTrigger() in:
public void mouseClicked(MouseEvent e)
{
if (e.isPopupTrigger())
{
// show popup
}
}