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

Restrict number of characters user can enter in a TextField

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • fx1.2
    • None
    • javafx

      I need to limit the number of characters user can enter in a text field. My approach is to build a custom TextField class as follows:

      public class CTextField extends TextField {
      attribute maxlen: Integer;
      override attribute onKeyTyped: function(event:KeyEvent)= function(event:KeyEvent) {
      if(text.length() >= maxlen)
      {
      event.source.consume();
      }
      };
      }

      TextField class should have an attribute such as maxlen that restricts number of characters allowed in the text box. This is a common data entry requirement. I shouldn't have to create a custom class to have this feature. This should be handled by TextField class.

            rbair Richard Bair (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: