• 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

Disabling Keybinding For Particular Component

 
Ranch Hand
Posts: 191
Netbeans IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your response Rob. I have will have a look at the linked page.
 
reply
    Bookmark Topic Watch Topic
  • New Topic