JDK-8090417 : maxLength in Texts Controls
  • Type: Enhancement
  • Component: javafx
  • Sub-Component: controls
  • Affected Version: fx2.1
  • Priority: P5
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2012-02-10
  • Updated: 2018-09-05
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Duplicate :  
Duplicate :  
Description
There was a feature like this, but it seems that it was talked about.

this feature would be very interesting in the TextField, and TextArea PasswordField.

Example: If max = 15, both the user input as the developer would be limited (truncated) to 15 characters.

In the textfield putting a method for filtering methods in this property (replaceText (int start, int end, String text) and ReplaceSelection (String text)).
This method would be something like:

private String checkMaxLen(String newString, int start, int end) {
      if( getLenght() >= getMaxLenght())  return null;

      int newLen = getLenght() + (end - start);
      if(newLen <= getMaxLenght()) return newString;
      String filteredNewString = newString.subString(0, getMaxLenght() - getLenght());
      return filteredNewString;
}


Although version 2.1 is closed, I think it is something very simple, very helpful for everyone.
Comments
Changing from feature to tweak, as my gut feeling is that this is something that may be implemented in less than two weeks. Leif is away at present, but Leif, please feel free to change back to feature if I am incorrect.
26-06-2012

as a matter of pasting, if the current text has 10 characters, your maxlen is 15, and we're pasting a text with 20 characters. Paste should first 5 characters and discard the rest.
10-02-2012

trim the text, to always keep the consistency.
10-02-2012

Take a look at the HTML 5 control set. See http://www.whatwg.org/specs/web-apps/current-work/multipage/common-input-element-attributes.html. They also use the term "maxLength". Restricting input to limit it to a number of characters is easy to do, but handling the cases where somebody (a) pastes a large number of characters in or (b) reduces the maxLength while a text already exists but is too long are a little more complicated. I would assume we allow the paste but limit it to the number of characters, and then have to decide what happens when you reduce the maxLength (trim the text?).
10-02-2012

This is related to RT-19402, which was closed because the functionality can easily be implemented by overriding the methods replaceText() and replaceSelection().
10-02-2012