I want to a JTextField to have maximum characters, Ive been trying out this code, what im trying to do is, if a user enters more then 13 characters it should erase the last character entered, I also tried with the Unicode Character (by replacing the \b to \u0008) but it gives the same result, this is my code:
if(EditTxtFName.getText().length() > 10)
{
EditTxtFName.setBackground(Color.red);
EditTxtFName.setText(EditTxtFName.getText() + "\b");
}
else
{
EditTxtFName.setBackground(Color.white);
}
The output of what happens is, instead of deleting the last character is adds space and continues.. Thanks in advance..