This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes How to recognize the ActionEvent in a FocusLost method?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to recognize the ActionEvent in a FocusLost method??" Watch "How to recognize the ActionEvent in a FocusLost method??" New topic
Author

How to recognize the ActionEvent in a FocusLost method??

Priya Sri
Ranch Hand

Joined: Mar 30, 2004
Posts: 84
Hi

I have a class which implements FocusListener,ActionListener. This Focus listener is used for a field named "Field 1" and the ActionListener is used for the buttons in the class. I have 2 buttons 'Save', 'Cancel'.

The validation for Field 1 should happen only for Save. The validation i am doing is the Field 1 should have 10 digits. If its not, it will throw error to the user.

The problem is when I click on 'Cancel' button, it is going into FocusLost() method and finding that "Field 1" is not having 10 digits and throwing error. Its not going into the actionPerformed() method of Cancel button. So, i was not able to execute Cancel button.

How will i identify that I clicked Cancel button (ActionEvent) in FocusLost() method??

Thanks in Advance
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

FocusEvent has a method called getOppositeComponent(). This returns the component that has gained the focus on focusLost events, and the component that has lost the focus on focusGained events.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Priya Sri
Ranch Hand

Joined: Mar 30, 2004
Posts: 84
Thanks Rob !!
Its working fine !!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to recognize the ActionEvent in a FocusLost method??
 
Similar Threads
Update/Set TextField from other class
Confirm message on submit
Problem refreshing a panel
Problem wth ActionListener Interface
validator in LookupDispachAction