This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I would like to know how to count the number of spaces in a JTextField which is limited in characters. For example, if I have a textField limited to 6 characters and I type the letter A , it should return me: A + 5 space because otherwise I'm forced to enter them manually.
I don't quite understand your requirement. There's a confusion between the contents of the text field at the time the user is entering data and the contents after that time.
To put it another way: if the user hasn't entered anything yet, should the value of the field be 6 blanks? And then what happens when the user tries to type a letter? Should it go at the beginning? Should the user be able to insert it at the end, after the 6 blanks? In the middle?
If you just want to pad the data with blanks to 6 characters after the user finishes entering the data, that's an entirely different (and much easier) question. So what I'm asking is, does the user have to be bothered with this padding requirement while they are entering the data, or does it only apply after they have finished?
Joined: Sep 17, 2010
Thanks a lot for your help
or does it only apply after they have finished?
Yes, that is what I want : pad data with blank after the user finishes entering data.
For exemple , if the max limit into my jtextfield is 6 characters and the user type the letter A, the value of the field must be A + 5 blanks , and if he hasn ' t entered anything yet , the value of the field must be 6 blanks.