CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 1999
    Location
    Portland, OR, USA
    Posts
    29

    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.

  2. #2
    Guest

    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...


  3. #3
    Join Date
    Apr 1999
    Posts
    3

    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.


  4. #4
    Guest

    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

  5. #5
    Guest

    Re: How to get mouse right-click

    actually,

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


  6. #6
    Join Date
    Apr 1999
    Location
    Portland, OR, USA
    Posts
    29

    Thanks for suggestions

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured