B4J Question Textfield autosize

Roger Daley

Well-Known Member
Licensed User
Longtime User
Hi All,

In using Textfield I find that the TF auto-resizes if the font is two large. This results in other views being overlaid by the Textfield.
My preference is to fix the the size of the TF [Desinger Script Textfield1.size = 20dip] and adjust the text size in code.

Does anyone know how to stop the Auto-resize?

Regards Roger
 

Daestrum

Expert
Licensed User
Longtime User
You should be able to set maxWidth and maxHeight on the textfield.
Probably need javaobject to do it.
B4X:
...
dim jo as JavaObject = theTextField
jo.runMethod*"setMaxWidth",array(100.0d))  ' set to maxWidth 100 pixels wide
jo.runMethod("setMaxHeight",array(20.0d))   '  set maxHeight to 20 pixels high
...
the values need to be Doubles - so 100.0d and 20.0d

note: if the font size wont fit heightwise, the textfield will resize the height automatically so it fits.
 
Last edited:
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime User
You should be able to set maxWidth and maxHeight on the textfield.
Probably need javaobject to do it.
B4X:
...
dim jo as JavaObject = theTextField
jo.runMethod*"setMaxWidth",array(100.0d))  ' set to maxWidth 100 pixels wide
jo.runMethod("setMaxHeight",array(20.0d))   '  set maxHeight to 20 pixels high
...
the values need to be Doubles - so 100.0d and 20.0d
note: if the font size wont fit heightwise, the textfield will resize the height automatically so it fits.
Thanks Daestrum, but it is the Auto-Resizing I need to stop.

Regards Roger
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
You could try this - it resizes the font dependent on the height of the textfield so should never make it grow
B4X:
' where tf is the textfield
dim fs as int = tf.PrefHeight /1.5
 tf.Style = tf.Style & "-fx-font-size: "& fs & "px;"
 
Upvote 0
Top