Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Focus Traversable  RSS feed

 
david joe
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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.
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Cindy,
Thank you very much. I really appreciate it.
 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!