-
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
-
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
-
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
-
By Andrew in forum VB Classic
Replies: 7
Last Post: 06-25-2009, 10:55 PM
-
By fulcanelli in forum Java
Replies: 10
Last Post: 11-06-2005, 03:29 PM
-
By me_code2004 in forum VB Classic
Replies: 1
Last Post: 09-11-2005, 02:02 AM
-
By DrunkinP in forum Java
Replies: 0
Last Post: 03-31-2005, 10:36 AM
-
By cinderella in forum Java
Replies: 2
Last Post: 03-03-2005, 04: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
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|