This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ActionListener - event is a tab?

 
John Davis
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My documentation refers only to the "Return" as an event which will trigger the ActionListener (for a JTextField). Can it work so that either a Tab or a Return event will trigger the ActionListener?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, sort of.

If you actually have you code in an Action class then have your "ActionLister" call the Action instead, then you can also add a FocusListener, which is needed to capture if the user has left the TextField, can also call the Action too, therefore reusing the Action class and not having duplicate Code.

You can also implement a KeyListener for getting which key is pressed, but I think the functionality you are looking for with Return and Tab is best implemented in the FocusListener instead, maybe.

Mark
 
Mike Lipay
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, I was looking for how to do this as well...ain't searches great!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic