-
Bug
-
Resolution: Unresolved
-
P4
-
None
-
1.4.1, 1.4.2
-
x86
-
windows_2000, windows_xp
Name: jk109818 Date: 08/19/2003
FULL PRODUCT VERSION :
java version "1.4.1_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_02-b06)
Java HotSpot(TM) Client VM (build 1.4.1_02-b06, mixed mode)
FULL OS VERSION :
Microsoft Windows 2000 [Version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
When combining the JFormattedTextField with the SimpleDateFormat, setting "AllowsInvalid" false, alpha characters are not ignored in certain positions and backspace and erase gives unexpected behaviour.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Put this in a JFrame:
..
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
JFormattedTextField tf = new JFormattedTextField(sdf);
tf.setValue(new Date());
((DateFormatter)tf.getFormatter()).setAllowsInvalid(false);
..
1) Position the caret just before the last numeric character (in the example between '1' and '4'). Type an 'a'. With my date it now changes to "2003-07-01" (in any other caret-position it would just get ignored)
2) If the caret is positioned anywhere in the text (but before the first character), and you press 'backspace', it modifies the whole date in some unpredictable way.
3) If the caret is positionen anywhere in the text (but after the last character), and you press 'delete', it modifies the whole date in some unpredictable way.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
1) That nothing would happen.
2) That the character to the left is erased, or nothing happens
3) That the character to the rigth is erased or nothing happens
ACTUAL -
Read under "Steps to reproduce"
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.text.DateFormatter;
public class DateError extends JFrame {
DateError() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
JFormattedTextField tf = new JFormattedTextField(sdf);
tf.setValue(new Date());
((DateFormatter)tf.getFormatter()).setAllowsInvalid(false);
getContentPane().add(tf);
pack();
setVisible(true);
}
public static void main(String[] args) {
new DateError();
}
}
---------- END SOURCE ----------
(Incident Review ID: 191350)
======================================================================