Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
The moose likes Swing / AWT / SWT and the fly likes ActionListener - event is a tab? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "ActionListener - event is a tab?" Watch "ActionListener - event is a tab?" New topic

ActionListener - event is a tab?

John Davis
Ranch Hand

Joined: Nov 02, 2000
Posts: 189
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

Joined: Feb 05, 2001
Posts: 17260

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.


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Mike Lipay
Ranch Hand

Joined: Sep 11, 2007
Posts: 171
Thank you, I was looking for how to do this as well...ain't searches great!
Have you tried LearnNowOnline?
subject: ActionListener - event is a tab?