-
Bug
-
Resolution: Fixed
-
P2
-
1.4.0
-
beta2
-
generic, x86
-
generic, windows_2000
-
Verified
On incrementing the Month field, MMMMM format, of Date in JFormattedTextField with cursoring feature, the number of characters selected is of the previous value in the Month field, whereas it should be of current value/month.
For ex : If you have incremented from 'February' to 'March', it selects 8(length of 'February') characters instead of 5(length of 'March') characters.
To reproduce, compile and run the following code :
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.JFormattedTextField.*;
import javax.swing.text.*;
public class TestJFTField extends JFrame {
JFormattedTextField jftFld;
DateFormatter formatter;
Robot robo;
TestJFTField() {
super("JFormattedTextField");
setSize(400,400);
getContentPane().setLayout(null);
jftFld = new JFormattedTextField(new Date());
jftFld.setBounds(40,40,200,30);
getContentPane().add(jftFld);
formatter = (DateFormatter)jftFld.getFormatter();
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat( "MMMMM dd yyyy");
formatter.setFormat(new java.text.SimpleDateFormat("MMMMM dd yyyy"));
jftFld.setValue(new Date());
JButton btn = new JButton("Test");
btn.setBounds(40,130,200,30);
getContentPane().add(btn);
setVisible(true);
addWindowListener( new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(1);
}
});
try {
robo = new Robot();
}
catch(AWTException e) { e.printStackTrace(); }
for( int i=0; i<12; i++ ) {
robo.keyPress(KeyEvent.VK_UP);
robo.delay(500);
robo.keyRelease(KeyEvent.VK_UP);
robo.delay(2000);
}
}
public static void main(String[] args)
{
System.out.println("Hello World!");
new TestJFTField();
}
}
For ex : If you have incremented from 'February' to 'March', it selects 8(length of 'February') characters instead of 5(length of 'March') characters.
To reproduce, compile and run the following code :
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.JFormattedTextField.*;
import javax.swing.text.*;
public class TestJFTField extends JFrame {
JFormattedTextField jftFld;
DateFormatter formatter;
Robot robo;
TestJFTField() {
super("JFormattedTextField");
setSize(400,400);
getContentPane().setLayout(null);
jftFld = new JFormattedTextField(new Date());
jftFld.setBounds(40,40,200,30);
getContentPane().add(jftFld);
formatter = (DateFormatter)jftFld.getFormatter();
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat( "MMMMM dd yyyy");
formatter.setFormat(new java.text.SimpleDateFormat("MMMMM dd yyyy"));
jftFld.setValue(new Date());
JButton btn = new JButton("Test");
btn.setBounds(40,130,200,30);
getContentPane().add(btn);
setVisible(true);
addWindowListener( new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(1);
}
});
try {
robo = new Robot();
}
catch(AWTException e) { e.printStackTrace(); }
for( int i=0; i<12; i++ ) {
robo.keyPress(KeyEvent.VK_UP);
robo.delay(500);
robo.keyRelease(KeyEvent.VK_UP);
robo.delay(2000);
}
}
public static void main(String[] args)
{
System.out.println("Hello World!");
new TestJFTField();
}
}
- duplicates
-
JDK-4466559 Selection Bug in JFormattedTextField when Full DateFormat is used
-
- Closed
-