JackLametta
JackLametta

Reputation: 410

MaskFormatter of jFormattedTextField deletes inserted value

I created a format for my jFormattedTextField

MaskFormatter formatter = new MaskFormatter("###.###.###.###");
formatter.setValidCharacters("0123456789");
jFormattedTextField7 = new javax.swing.JFormattedTextField(formatter);

but anytime I try to insert a value in the jFormattedTextField, switching to another one to insert an input value, the one in the code gets empty again.

enter image description here

enter image description here

Upvotes: 0

Views: 170

Answers (1)

camickr
camickr

Reputation: 324118

You haven't entered a number in each position, therefore it is considered invalid. Try:

textField.setFocusLostBehavior(JFormattedTextField.COMMIT);

Upvotes: 2

Related Questions