File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java 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
JavaRanch » Java Forums » Java » Beginning Java
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: 17276

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 - iOS Apps
How to Ask Questions the Smart Way FAQ
I agree. Here's the link:
subject: ActionListener - event is a tab?
It's not a secret anymore!