Assosciating Keyboard button with Mouse Right button


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Assosciating Keyboard button with Mouse Right button

  1. #1
    Join Date
    Dec 2005
    Posts
    5

    Thumbs down Assosciating Keyboard button with Mouse Right button

    Hi Guys,

    There is one problem i am facing in java swings application.
    I have one JPopupMenu which is invoked when we use the right button of our mouse. But when i use the keyboard button to invoke the right click menu it does not work.

    In windows envoirment the properties button which is adjacent to the windows key on the keyboard is equivalent to right click of mouse.

    But why this is not workable in java AWT or Swings applications.
    Does java support this or we hve to add some code to make that key workable. Or is there any way thru wich i can invoke the JPopupMenu when user press a key which has a keyCode = 525 .

    Plz reply me as soon as possible.

    Thanks in advance.

    Cheers

    Akshat

  2. #2
    Join Date
    Aug 2003
    Posts
    313
    You should be able to show it whenever you want to. If you can have a listener respond to that key then you should be able to do something like:
    Code:
    popup.show(e.getSource(), left, top);
    There should be a way to get the coordinates of the mouse at any given time, but I'm not entirely positive how you do it.

    Hope this helps.
    ~evlich

  3. #3
    Join Date
    Dec 2005
    Posts
    5
    Thnks evlich for ur response....

    but there is one way tht i want tell u is to use InputMap if some one wants to generate popup menu on pressing ctrl + spacebar.


    InputMap map = panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

    map.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, InputEvent.CTRL_MASK),"postMenuAction");

    panel.getActionMap().put( "postMenuAction", new ActivatePopupMenuAction(this,treePopupMenu));



    i hve tried even this but this sucks. As my application is extending JFrame and JFrame has no getInputMap() or getActionMap().
    So this will run fine if u hve some application extending JPanel.

    Now what i hve to done to open Popup menu is that I implemented KeyListener interface and in keypressed method i inserted ur code which works absolutely fines.

    Well Thnks for ur reply
    Cheers
    Akshat

Similar Threads

  1. Disable keyboard, keep mouse working
    By Andrew in forum VB Classic
    Replies: 7
    Last Post: 06-25-2009, 10:55 PM
  2. Linking a button click to a mouse event?
    By fulcanelli in forum Java
    Replies: 10
    Last Post: 11-06-2005, 02:29 PM
  3. Replies: 1
    Last Post: 09-11-2005, 02:02 AM
  4. button listener not working
    By DrunkinP in forum Java
    Replies: 0
    Last Post: 03-31-2005, 09:36 AM
  5. Move a button with mouse
    By cinderella in forum Java
    Replies: 2
    Last Post: 03-03-2005, 03:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center