Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4434198

Month not selected properly with cursoring in JFormattedTextField (Date format)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 1.4.0
    • 1.4.0
    • client-libs
    • 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();
      }
      }

            svioletsunw Scott Violet (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: