how to set textField.setWidth with the same of textField.setMaxLength

Hi, how can I set the width with the same sapace for maxLength

example

I have the maxlength to 20, so I need to setWidth to size that the limmit is 20 character

I have try all Unit size but I didn’t found one way to di that

public enum Unit {
/**
* Unit code representing pixels.
/
PIXELS(“px”),
/
*
* Unit code representing points (1/72nd of an inch).
/
POINTS(“pt”),
/
*
* Unit code representing picas (12 points).
/
PICAS(“pc”),
/
*
* Unit code representing the font-size of the relevant font.
/
EM(“em”),
/
*
* Unit code representing the font-size of the root font.
/
REM(“rem”),
/
*
* Unit code representing the x-height of the relevant font.
/
EX(“ex”),
/
*
* Unit code representing millimeters.
/
MM(“mm”),
/
*
* Unit code representing centimeters.
/
CM(“cm”),
/
*
* Unit code representing inches.
/
INCH(“in”),
/
*
* Unit code representing in percentage of the containing element
* defined by terminal.
*/
PERCENTAGE(“%”);

Well, Unit.EM is your best bet. Most typefaces are variable-width, so obviously the string “iiiiiiiiii” is narrower on screen than “mmmmmmmmmm”, even though both have 10 letters. If you really need the width to always match the max length, you’ll have to use Unit.EM in combination with a fixed-width or “monospace” font - be aware that this will probably not look good except in special circumstances.

Thanks a lot, your answer was usefull!