Restrict input length

Hi,

After havning read the posts here, i see that a lof of suggestions to use JFormattedTextField with a MaskFormatter.

The only problem is that if the field is reused then there is a formatting problem.

Let me elucidate, i have a field that says enter a max of 25 characters, when i enter it the first time process it and then display results. now when i want to change the entry in the field, if i go in the middle and delete somehting it acts strange...

please do try this

pieceId =new JFormattedTextField(new MaskFormatter("*************************"));

and let me know....

when i try to edit pieceId the second time over...the issue arises.

if someone has a better solution do let me know.

Thank You.

-Uday

[873 byte] By [uday_prakasha] at [2007-11-27 2:31:09]
# 1

if you just want to restrict the length, try a DocumentFilter

[url]http://java.sun.com/docs/books/tutorial/uiswing/components/generaltext.html#filter[/url]

example:

http://java.sun.com/docs/books/tutorial/uiswing/events/documentlistener.html

scroll to bottom of page and click the links for TextComponentDemo and

DocumentSizeFilter. the input 'max' length is 300, so start typing then see what

happens when chars = 300

Michael_Dunna at 2007-7-12 2:45:40 > top of Java-index,Desktop,Core GUI APIs...
# 2
Thank you!man that hit the nail on the head... very useful.-Uday
uday_prakasha at 2007-7-12 2:45:40 > top of Java-index,Desktop,Core GUI APIs...