aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Arrow Keys not working in JMenu Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Arrow Keys not working in JMenu" Watch "Arrow Keys not working in JMenu" New topic
Author

Arrow Keys not working in JMenu

Tahir Abbas
Ranch Hand

Joined: May 05, 2007
Posts: 45
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.
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2503
    
    8

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.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5 OCPBCD5
Tahir Abbas
Ranch Hand

Joined: May 05, 2007
Posts: 45
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

Joined: Sep 13, 2007
Posts: 2503
    
    8

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

Joined: May 05, 2007
Posts: 45
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

Joined: Sep 13, 2007
Posts: 2503
    
    8

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Arrow Keys not working in JMenu