• 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

Arrow Keys not working in JMenu

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

In my application menu bar appears properly and it works good with mouse but Arrow keys, Enter and Esc keys dont work. I am using Eclipse.

I will highly appreciate any help in this regard.

Thanks! in Advance.
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Arrow keys? How are you accessing your menu using the keyboard? Alt key? Did you add those mnemonics for the menus and menu items? Supposedly once a menu or item is selected with the keyboard, hit enter to select it. And once a menu is selected I'm sure the arrow keys will work moving your current position or selected item/menu up/down/left/right.
 
Tahir Abbas
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am copying some sample code from my programme. I can use menu bar with mouse. AcceleratorKeys work, Alt+F moves control to menu bar but I cannot move from one menu item to other with the help of arrow keys as well as Enter and Esc Keys also dont work.


Thanks!
 
K. Tsang
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your given code looks fine except you didn't add the menu items to the menu. About those enter and esc keys... if you don't have the menu selected they don't do anything, same for arrow keys.

Default your app central panel has the control (eg your JTable when you get to that). So when app runs, all keys don't do anything until you do "ALT+F" to select the file menu then the menu items show up. Oh your code doesn't have mnenomic for Search, despite you have for the menu items.

have you done your action listeners? Try outputting something when you trigger the menu item using mouse or enter key.

Oh just a tip for your search, your first 2 menu items (name, location) are really name only and location only respectively meaning the OR logic. This makes your 3rd menu item the AND (eg name AND location).

If you run my code your keys will work.

 
Tahir Abbas
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks! K. Tsang,

Infact to cover many things in less lines I didn't copy all code. It has add menu items, mnenomic and accelerator keys for Search by Name Location and for Name or/and Location search. Action listeners are also working good, showing result in JTable in the center. But menu does not work with keyboard, only Alt+F works then Arrow Keys, Enter or Esc does not work.

Now I am going to copy all my project in new workspace, may be it'll solve the problem.
Thanks!
 
K. Tsang
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You know what, if you can't get the menu bar to work.... why not don't use one. It's not a must to have menu bar and menus. Of course having one does make it more like a GUI.
 
reply
    Bookmark Topic Watch Topic
  • New Topic