• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Focus Traversable

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know isFocusTraversable of Component returns the value of a flag that indicates whether this component can be traversed using Tab or Shift-Tab keyboard focus traversal. But I don't know how to make certain component in my container to be not Tab Traversable or to be Tab Traversable. Is there any attribute on Component that I could set to achieve that? Or if there is anyway to do that at all? Anyone could help? Thanx.
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you put a focusListener on the component and then when it gets focus do a transferFocus() it will move on to the next component - effectively skipping this one.
 
david joe
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cindy,
Thank you very much. I really appreciate it.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While transferFocus() works, the "Politically correct way", or so Sun says, is to create your own textfield class that extends JTextfield, and override the isFocusTraversible() method to return false, and then the FocusManager will skip over the textfield.
Mark Spritzler
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would retract and say that transferFocus() is great for making the Enter key act like the Tab key. But I still like the elegance of overriding the isFocusTraversible() method to make a JTextField Read-only
Mark
 
Create symphonies in seed and soil. For this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic