You can write your own class that extends from Document or PlainDocument.
Ex.:
textField.setDocument(new LimitDocument(255)); // cannot type more than 255
chars into this text field
However, it will not prevent the users from pasting more text into this
component. You may have to intercept paste event and strip the data that is
to be copied in the component in that case, unless there's a simpler
solution for this problem that I am now aware of.
// ------------------
class LimitDocument extends PlainDocument
{
private int limit;
public LimitDocument(int limit)
{
super();
setLimit(limit); // store the limit
}
public final int getLimit()
{
return limit;
}
/** intercept the string we want to enter into a text component */
public void insertString(int offset, String s, AttributeSet
attributeSet)
throws BadLocationException
{
// if we haven't reached the limit, insert the string
if(offset < limit)
{
super.insertString(offset,s,attributeSet);
} // otherwise, just lose the string
}
public final void setLimit(int newValue)
{
this.limit = newValue;
}
}
-----Original Message-----
From: baski [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, March 27, 2002 6:11 AM
To: Norell Peter; Reinstein, Lenny; '[EMAIL PROTECTED]'
Subject: Re:Editing a JTable cell on double-click.
Hi..all..
can anyone tell me huw to set the text entry in a text
field..(for example, more than 6 characters shld not
be allowed to enter in that text field)..
thanx in advance
baskie
__________________________________________________
Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards�
http://movies.yahoo.com/
_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing