Limiting number of characters a user can enter in a JTextField - Netbeans?
807601May 22 2008 — edited May 24 2008I have a form in Netbeans with a JTextField.
I want to limit the number of characters a user can enter into this field.
In my source code I have:
int strLen;
String fName = fName_text.getText(); //fName_text is the JTextField on my form.
if((strLen = fName.length()) >25){
JOptionPane.showMessageDialog(null,"FIRST NAME IS LIMITED TO 25 CHARACTERS","NOTICE",JOptionPane.INFORMATION_MESSAGE);}
else
{
//Stop the application and leave the focus on this field.
}
How do I write the code that will stop the application from running? ...and leave the focus on this JTextField so the user can enter the correct amount of characters?