I am trying to automatically add a space between character groups in a TextTield
.
When user enters 8 digits I want to insert a space between the first- and last four digits:
12345678 => 1234 5678
I am trying to automatically add a space between character groups in a TextTield
.
When user enters 8 digits I want to insert a space between the first- and last four digits:
12345678 => 1234 5678
Try JFormattedTextField
that allows you set an input mask.
MaskFormatter mask = null;
try {
mask = new MaskFormatter("#### ####");
mask.setPlaceholderCharacter(' ');
} catch (ParseException e) {
e.printStackTrace();
}
JFormattedTextField textfield = new JFormattedTextField(mask);