This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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.
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.
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.
Joined: May 05, 2007
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.