aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Retaining Focus in Swing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Retaining Focus in Swing" Watch "Retaining Focus in Swing" New topic
Author

Retaining Focus in Swing

Ravi Kanth D
Greenhorn

Joined: Sep 14, 2003
Posts: 18
Upon validating a JTextField value on the focusLost event, how do I retain the focus back on the same JTextField until correct value is entered? Thanks.
Ravi.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

You should be able to call requestFocus() on the JTextField.


GenRocket - Experts at Building Test Data
Ravi Kanth D
Greenhorn

Joined: Sep 14, 2003
Posts: 18
I tried but doesn' work. This is what I am doing...please let me know if I am wrong:
In focusLost event, I said if length() is < 4 then show an error message on the bottom text area...and requestFocus()
When I do not enter a value in first control and click on the second control...it does display the error message correctly...but cursor is still in the second control... I want it to come back to first control. How do I do it? Thanks.
Ravi.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

You'll have to excuse the horrible looking GUI here, but this works for me.
Ravi Kanth D
Greenhorn

Joined: Sep 14, 2003
Posts: 18
Earlier I did something stupid...so it didn' work. Thx for your help again.
Ravi.
Garandi Garandi
Ranch Hand

Joined: Jan 07, 2003
Posts: 192
Try inputListener

I hope this will help
Thank you
Garandi
VIJAY Yadlapati
Ranch Hand

Joined: Aug 04, 2003
Posts: 175
Try InputVerifier.
see InputVerifier. There is an example also..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Retaining Focus in Swing