[英]Why is JFormattedTextField restoring previous value?
I am using a JFormattedTextField, when i try to delete the value in the field, it automatically restores the previous value. 我正在使用JFormattedTextField,当我尝试删除字段中的值时,它会自动恢复以前的值。 What is the reason for this behaviour and how can i stop it restoring the value? 这种行为的原因是什么?如何阻止它恢复价值?
This is the code for JFormattedtextField. 这是JFormattedtextField的代码。
jFormattedTextField2 = new javax.swing.JFormattedTextField(new DecimalFormat("###,###.##"));
It happens because JFormattedTextField
allows configuring what action should be taken when focus is lost using the setFocusLostBehavior
method. 这是因为JFormattedTextField
允许配置使用setFocusLostBehavior
方法丢失焦点时应采取的操作。
These are the actions. 这些都是行动。
Description 描述
JFormattedTextField.REVERT
- Revert the display to match that of getValue, possibly losing the current edit.JFormattedTextField.REVERT
- 恢复显示以匹配getValue的显示,可能会丢失当前编辑。
JFormattedTextField.COMMIT
- Commits the current value.JFormattedTextField.COMMIT
- 提交当前值。 If the value being edited isn't considered a legal value by the AbstractFormatter that is, a ParseException is thrown, then the value will not change, and then edited value will persist. 如果正在编辑的值不被AbstractFormatter视为合法值,则抛出ParseException,则该值不会更改,然后编辑的值将保持不变。
JFormattedTextField.COMMIT_OR_REVERT
- Similar to COMMIT, but if the value isn't legal, behave like REVERT.JFormattedTextField.COMMIT_OR_REVERT
- 与COMMIT类似,但如果值不合法,则表现得像REVERT。
JFormattedTextField.PERSIST
- Do nothing, don't obtain a new AbstractFormatter, and don't update the value.JFormattedTextField.PERSIST
- 什么都不做,不要获取新的AbstractFormatter,也不要更新值。
**** The default is JFormattedTextField.COMMIT_OR_REVERT
so when you enter an invalid value, it's reverted and you get the previous consistent state** ****默认值为JFormattedTextField.COMMIT_OR_REVERT
因此当您输入无效值时,它将被还原并获得之前的一致状态**
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.