This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes LostFocus and SwingUtilities.invokeLater() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "LostFocus and SwingUtilities.invokeLater()" Watch "LostFocus and SwingUtilities.invokeLater()" New topic

LostFocus and SwingUtilities.invokeLater()

dharmesh baveja

Joined: Dec 18, 2000
Posts: 13
I am facing proble , which is as below:
1.I have got a JtextField on which i am doing validation on lostfocus()
2.But when one clicks the some button on Frame and focus was on the JTextField , two things happen:
a)Lost Focus happens on JtextField.
b)Jbutton_action_perfomed happens.
3. I want on such a click on button , the validation to be skipped out.
4. I think i can handle this case by invokelater() , but how?
5.Desired is:
1. On lostfocus , validation() will be excuted and returning focus back to JTextFiled.
2.On button click , i want to skip the execution of validation() by setting flag & skipping the run method of thread in invokelater(). This can be done in button_actionprformed().
Please send me the rough outline code for:
2.processing to be done in button_actionperformed().
Pls help me urgently!!
Thanks in advance.
Laurent Leonard
Ranch Hand

Joined: May 15, 2001
Posts: 35
If youare using Java 1.3 or later, you can use the class InputVerifier.
And if you want to avoid the check (for example with a cancel button), you can see the method setVerifyInputWhenFocusTarget.

You can look also to the class PlainDocument if you want some
"clever" behaviour for your widget.

Laurent Leonard

Have you checked out Aspose?
subject: LostFocus and SwingUtilities.invokeLater()
It's not a secret anymore!