-
Bug
-
Resolution: Unresolved
-
P4
-
None
-
5.0, 6
-
x86
-
windows_2000, windows_xp
FULL PRODUCT VERSION :
java version "1.5.0_08"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_08-b03)
Java HotSpot(TM) Client VM (build 1.5.0_08-b03, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows 2000 [Version 5.00.2195]
SunOS zcars0zp 5.8 Generic_117350-33 sun4u sparc SUNW,Netra-T12
A DESCRIPTION OF THE PROBLEM :
JSpinner SpinnerListModel, if user inputs invalid value that is no the in List, the commitEdit function does not throws exception and the JSpinner set back to the old value which is incorrect behavior.
This also cause the problem when set the JFormattedTextField.setFocusLostBehavior(JFormattedTextField.COMMIT), when the component lost focus, if the user input is invalid, it will back to the old value. This behavior is not consistent with the SpinnerNumberModel.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
For JSpinner, if the user input is invalid, the commitEdit should throw an Exception.
If set to setFocusLostBehavior(JFormattedTextField.COMMIT), when the component lost focus, invalid input should not back to old value.
ACTUAL -
JSpinner SpinnerListModel, if the user input is invalid, the commitEdit does not throw an Exception and back to old value.
If set to setFocusLostBehavior(JFormattedTextField.COMMIT), when the component lost focus, invalid input will back to old value.
REPRODUCIBILITY :
This bug can be reproduced always.
CUSTOMER SUBMITTED WORKAROUND :
Current, I set the JSpinner JFormattedTextField.setFocusLostBehavior(JFormattedTextField.PERSIST) and does not call commitEdit function. I am using the ((JSpinner.DefaultEditor)jspinner.getEditor()).getTextField().getText() to get the user input and verify whether it is valid.
The problem is in the file JSpinner.java
public static class ListEditor extends DefaultEditor
{
......
private class ListFormatter extends
JFormattedTextField.AbstractFormatter {
........
public Object stringToValue(String string) throws ParseException {
return string; // <--- Here, need to valid the user input and throws exception.
}
}
I know the list mode does not know the Object type, but at least it can use the Object.toString() and compare to the user input. Alternate solution is user can define that interface in the ListEditor.
java version "1.5.0_08"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_08-b03)
Java HotSpot(TM) Client VM (build 1.5.0_08-b03, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows 2000 [Version 5.00.2195]
SunOS zcars0zp 5.8 Generic_117350-33 sun4u sparc SUNW,Netra-T12
A DESCRIPTION OF THE PROBLEM :
JSpinner SpinnerListModel, if user inputs invalid value that is no the in List, the commitEdit function does not throws exception and the JSpinner set back to the old value which is incorrect behavior.
This also cause the problem when set the JFormattedTextField.setFocusLostBehavior(JFormattedTextField.COMMIT), when the component lost focus, if the user input is invalid, it will back to the old value. This behavior is not consistent with the SpinnerNumberModel.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
For JSpinner, if the user input is invalid, the commitEdit should throw an Exception.
If set to setFocusLostBehavior(JFormattedTextField.COMMIT), when the component lost focus, invalid input should not back to old value.
ACTUAL -
JSpinner SpinnerListModel, if the user input is invalid, the commitEdit does not throw an Exception and back to old value.
If set to setFocusLostBehavior(JFormattedTextField.COMMIT), when the component lost focus, invalid input will back to old value.
REPRODUCIBILITY :
This bug can be reproduced always.
CUSTOMER SUBMITTED WORKAROUND :
Current, I set the JSpinner JFormattedTextField.setFocusLostBehavior(JFormattedTextField.PERSIST) and does not call commitEdit function. I am using the ((JSpinner.DefaultEditor)jspinner.getEditor()).getTextField().getText() to get the user input and verify whether it is valid.
The problem is in the file JSpinner.java
public static class ListEditor extends DefaultEditor
{
......
private class ListFormatter extends
JFormattedTextField.AbstractFormatter {
........
public Object stringToValue(String string) throws ParseException {
return string; // <--- Here, need to valid the user input and throws exception.
}
}
I know the list mode does not know the Object type, but at least it can use the Object.toString() and compare to the user input. Alternate solution is user can define that interface in the ListEditor.