There is a TextField
inside a Container
and other components
in the Form
. According to the available space for the Container
the TextField
has a preferred width
. How can I set programmatically a maxSize
, that is the maximum number of characters
that can be entered , to the TextField
?
Asked
Active
Viewed 331 times
2
1 Answers
2
For set a maximum number of characters to a TextField
you should use setDefaultMaxSize(int value)
. So, you must catch the width of the Container
and set this maxSize according to this size.

Mun0n
- 4,438
- 4
- 28
- 46
-
But there is the problem of the font size ! And every letters have not the same size ! So how to know how many caracters should be set ? – pheromix Feb 03 '12 at 09:21
-
I use to do it by hand. Catch the fontSize too and modify the setDefaultMaxSize. Did you try with setGrowByContent? – Mun0n Feb 03 '12 at 09:39
-
maxSize and width of container are not the same ; the former is the nb of chars and the last is mesurement in pixel ! – Feb 08 '12 at 08:05