I'm in the process of creating a JTextField that will only contain integers. I want to prevent only having a - sign and a null string. Is there a way in Java to be notified when the JTextField loses focus, so I can perform the last checks on the input data?
Zoe, Yes, what you would do is to add a FocusListener to the JTextField and use its focusLost( FocusEvent e ) method to handle this... Personally, I would either have it blank the field, or return focus to the field and pop up a warning message... HTH, -Nate
-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
zoe goddard
Ranch Hand
Joined: Dec 12, 2000
Posts: 74
posted
0
Thanks, Your suggestions are along the same lines that I was going to to do. I just want to force them to input a number, blanks for these fields don't make sense in my application.
Kris Schneider
Ranch Hand
Joined: Feb 14, 2001
Posts: 71
posted
0
If you're using J2 v1.3, you might want to look into the javax.swing.JComponent.setInputVerifier(InputVerifier) method and the javax.swing.InputVerifier class.