File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Disabling Keybinding For Particular Component Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Disabling Keybinding For Particular Component" Watch "Disabling Keybinding For Particular Component" New topic
Author

Disabling Keybinding For Particular Component

Isaac Hewitt
Ranch Hand

Joined: Jul 24, 2006
Posts: 190

I have attached events to certain keystrokes in order to allow a user to consult a list of images viewable in a JScrollPane within a JFrame. Left and right arrow keys allow the user to go forward or backward through the list of images. Up and down arrow keys allow the image to be blown up or reduced in size. Several other keystrokes have events attached to that should only affect the images. I recently added a JList, containing the 26 letters of the alphabet, to the NORTH region of the JFrame, and this component seems to want to steal the show with regards to keybinding. Now when it has the focus, and it usually does, and an upward or downward arrow key is used, a new letter in the JList is selected. Keybinding for the JScrollPane no longer works unless focus on the JList is lost. Only if the TAB key is first pressed does keybinding as programmed fall back to the JScrollPane inside the JFrame.

I want to be able to permanently disable the default keybinding for the JList, so if ever it has focus no keystrokes can affect its behaviour.
Thanks.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2180
    
    7
Only if the TAB key is first pressed does keybinding as programmed fall back to the JScrollPane inside the JFrame.


Yes, KeyStrokes are first handle by the component with focus. You need to understand how the (3) different types of InputMaps work. Key Bindings explains some of the basics and contains a link to the Swing tutorial which explains bindings in more detail.

Isaac Hewitt
Ranch Hand

Joined: Jul 24, 2006
Posts: 190

Thank you for your response Rob. I have will have a look at the linked page.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Disabling Keybinding For Particular Component