Type TextMetric(Width As Double, Height As Double)
Private TextArea1 As TextArea ' or B4XView
Dim myString As String = $"Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown
printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries,
but also the leap into electronic typesetting, remaining essentially unchanged."$
Dim TM As TextMetric = MeasureText(myString,fx.DefaultFont(16)) 'same font size set in designer
Sleep(0) 'This solved issue with other view height changes as well.
'TextArea1.SetLayoutAnimated(0, TextArea1.Left, TextArea1.Top , TextArea1.Width, (TM.Width / TextArea1.Width) * (TM.Height * 1.5)) 'As B4XView
TextArea1.PrefHeight = (TM.Width/TextArea1.Width) * (TM.Height * 1.5) 'As Text Area ( 1.5 ?? )
TextArea1.Text = myString
Sub MeasureText(Text As String,TFont As Font) As TextMetric
Dim TM As TextMetric
TM.Initialize
Dim T As JavaObject
T.InitializeNewInstance("javafx.scene.text.Text",Array(Text))
T.RunMethod("setFont",Array(TFont))
TM.Width = T.RunMethod("prefWidth",Array(-1.0))
TM.Height = T.RunMethod("prefHeight",Array(TM.Width))
Return TM
End Sub