Hi,
Add keylistener to the concerned textfield and in the keypressed event write the following code
JTextField jTextField1=new JTextField();
jTextField1.setText(""); //intially the textfield is empty
void jTextField1_keyPressed(KeyEvent e) {
int len=jTextField1.getText().length();
System.out.println("hello1::"+len);
if(len>2)
{
jTextField1.setEditable(false);
}
else
{
jTextField1.setEditable(true);
}
}
This allows only three characters to be typed in the textfield.
U can clear the textfield by means a clear button and retype. Everytime u type fresh , u cannot enter more than 3 characters.
Hope this would be quite useful to u.
Regards
PremilaViswanathan
Originally posted by Sajee Joseph:
Hi,
I have a JTextField. I would like it to be 4 cloumn wide, but accept only 3 characters?
How do i do that?
..regards
..saj