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.
What i am trying in below lines to Delete the numeric char from myJTextField if its at first position.
But the thing i get is not what i expect.
If i enter 5 and then 7, it deletes the 5 but 7 remains in field.
Note : If i have used the e.consume() then i am not able to use numerics other then 1st position.
With your present code, what would be the result of pasting a digit by Ctrl-V?
There are no new questions, but there may be new answers.
Joined: Sep 10, 2008
Thanks for the help. Previously tried DocumentListener but didn't get much help.
With KeyListener, Ctrl-V append each digit to its predecessor.
But with my new code it is NULL. Thanks.
But the other side is that seems that it allows only one character and then throws exception (a NullPointerException without any specific function so not of much help to debug)
What i am trying to check is that first char must be an ALPHA (either Uppercase or Lowercase) but must not be a Numeric.
If i have used
then it was not allowing any character. Seems like it checks the ASCII values of entered char.
So you want the field to always start with a letter, if it contains anything at all? Seems to me you should be looking at some after-the-fact validation, rather than trying to interfere with what the user is typing in. Maybe a JFormattedTextField?
And by the way, checking that something is not a digit is an inadequate way to check that it is a letter.
Joined: Sep 10, 2008
Thanks for the valuable help.
I just added an ELSE block and the code works fine. btw now i am using a customized myFilter class in which i placed the below method.
My myFilter class extends PlainDocument which in turn extends AbstractDocument. So i am able to override replace method
My myFilter class restricts the input to Albhabets+Numeric+SomeSpecialCharacters but it starts with only an alphabet.
PS: Now the code also handle Ctrl-V for numerics at first position. Claps for Darryl.