jFormattedTextField的MaskFormatter删除插入的值

时间:2016-08-20 11:38:50

标签: java swing jformattedtextfield maskformatter

我为 jFormattedTextField

创建了一种格式
MaskFormatter formatter = new MaskFormatter("###.###.###.###");
formatter.setValidCharacters("0123456789");
jFormattedTextField7 = new javax.swing.JFormattedTextField(formatter);

但是当我尝试在 jFormattedTextField 中插入一个值时,切换到另一个值来插入输入值,代码中的那个值再次变空。

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:2)

您尚未在每个位置输入数字,因此被视为无效。尝试:

textField.setFocusLostBehavior(JFormattedTextField.COMMIT);