• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Disabling Keybinding For Particular Component

 
Isaac Hewitt
Ranch Hand
Posts: 191
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2599
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 191
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your response Rob. I have will have a look at the linked page.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic