• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

setting Keyboard shortcut for JPopupMenu

 
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Can any body know about How to add keyboard shortcut for JPopupMenu.
Like setMnemonic method for JButton.

Thanks in advance
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Shashidhar Rao:
Hi
Can any body know about How to add keyboard shortcut for JPopupMenu.
Like setMnemonic method for JButton.

Thanks in advance



I am presuming you are going to use JMenu and JMenuItem instead of JButton.
This is the way its typically done:
 
Shashidhar Yarabati
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Maneesh
Thanks for your prompt reply. Actually what my problem is I have used popup menus in my applcation. Some where else client is using this application and he using Mac mouse. It is having only one button. So, he can't able to see popup menu items.
So, if we have shortcut key to open popupmenu it will be easy for him.

I have gone through the API but I didn't found any such method till now. If you know solution for this please let me know..
Thanks in advance.

Shashi
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Shashidhar Rao:
Actually what my problem is I have used popup menus in my applcation. Some where else client is using this application and he using Mac mouse.



Hi Shashi,
My bad. I was under the impression you were talking about the mnemonics and accelerators for the popup.
I personally havent worked on a Mac machine. So my solution might be wrong.

The windows keyboards have a standard button which is mapped to the right click action/context menu/shift+F10 action You can probably follow the same approach. There is a convenient method called createRootPane which you can tweak to get your result. Here is some code:



I had used this to hide1 the dialog when you press the escape key. You can probably decide on some standard MacKeyboard button and use it instead of the escape.
 
Shashidhar Yarabati
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi again,
First of all I am not thinking about Mac machine. What I am thinking is How to create keyboard shortcut to open the popupmenu. For suppose I don't want to use mouse in application I want to open the popupmenu by keyboard.
Can you tell how to do this?

Thanks in advance..
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Shashidhar Rao:
Hi again,
First of all I am not thinking about Mac machine. What I am thinking is How to create keyboard shortcut to open the popupmenu. For suppose I don't want to use mouse in application I want to open the popupmenu by keyboard.
Can you tell how to do this?

Thanks in advance..



Thats easily done using the popup.show(Component invoker,int x,int y)
You will need to:
1) Override the createRootPane as I mentioned earlier. There you will need to register the key(s) which will trigger the popup
2) This will call a method which should accept the invoker component and the popup to be displayed. For this you will need some kind of mechanism to figure out which component is currently having the focus and the popup menus associated with it
3) You will have to then figure out the x and y coordinates of the currently focused component and then display the popup accordingly.

Hope this helps.
Best of luck.
 
Shashidhar Yarabati
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, I hope I will get now...
 
Shashidhar Yarabati
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Maneesh again
I registered one key. Then How would we know the key is fired in our code.
So, that I can call particular method.

Please help me in this regard...
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Shashidhar Rao:
Hi Maneesh again
I registered one key. Then How would we know the key is fired in our code.
So, that I can call particular method.

Please help me in this regard...



Refer to the createRootPane() I posted. You need to override it in your base frame.
Inside that you register the keys by using


Also you call your method from there itself. My example calls performActionCancel(). Similarly you need to call your method.
 
reply
    Bookmark Topic Watch Topic
  • New Topic