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

InternationalFormatter inserts text incorrectly

XMLWordPrintable

    • b105
    • x86
    • windows_2000
    • Verified

      J2SE Version (please include all output from java -version flag):
      java version "1.6.0-rc"
      Java(TM) SE Runtime Environment (build 1.6.0-rc-b96)
      Java HotSpot(TM) Client VM (build 1.6.0-rc-b96, mixed mode, sharing)

      Does this problem occur on J2SE 1.4.x or 5.0.x ? Yes / No (pick one)
      Yes

      Operating System Configuration Information (be specific):
      Microsoft Windows 2000 [Version 5.00.2195]

      InternationalFormatter inserts text incorrectly

      1) Run the following code
      2) Insert the cursor between the 0 and the %
      3) Type 5

      Expected: you should see 5%
      Actual: you still see 0%

      InternationalFormatter is incorrectly inserting the 5 after the % sign (0%5 instead of 05%),
      and then attempting to parse it.

      import java.text.*;
      import javax.swing.*;
      import static javax.swing.JFrame.*;
      import javax.swing.text.*;

      public class Test {
        public static void main(String[] args) {
          JFrame frame = new JFrame();
          NumberFormatter formatter = new NumberFormatter(NumberFormat.getPercentInstance());
          formatter.setAllowsInvalid(false);
          formatter.setCommitsOnValidEdit(true);
          formatter.setOverwriteMode(false);
          JFormattedTextField textField = new JFormattedTextField(formatter);
          textField.setEditable(true);
          textField.setValue(0);
          frame.add(textField);
          frame.pack();
          frame.setVisible(true);
          frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
        }
      }

            peterz Peter Zhelezniakov
            tyao Ting-Yun Ingrid Yao (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: