Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Type TextMetric (Width AsInt,Height AsInt)
End Sub
Sub AppStart (Form1 As Form, Args() AsString)
MainForm = Form1
MainForm.Show
Dim TM As TextMetric = MeasureText2("Test Line Test Line Test Line Test Line Test Line Test Line", 100, fx.CreateFont("Arial", 18, False, False))
Log(TM.Width)
Log(TM.Height)
End Sub
Sub MeasureText2(Text As String, Width As Int, mFont as Font) As TextMetric
Dim TM As TextMetric
TM.Initialize
'Create a dummy form
Dim MForm As Form
MForm.Initialize("",-1,-1)
'And hide it off the screen
MForm.WindowTop = - 1000
'MForm.WindowLeft = - Width - 200
Dim LJO,Bounds As JavaObject
'Create a label
Dim L As Label
L.Initialize("")
'Let it wrap the text
L.WrapText = True
' font
L.Font = mFont
'Assign the text to test
L.Text = Text
'Add it to the forms rootpane
MForm.RootPane.AddNode(L,10,10,Width,-1)
'Show the form
MForm.Show
'Initialize the JavaObject
LJO = L
'Get the bounds
Bounds = LJO.RunMethod("getLayoutBounds",Null)
'Set the return values
TM.Width = Bounds.RunMethod("getWidth",Null)
TM.Height = Bounds.RunMethod("getHeight",Null)
'And Close the Dummy form
MForm.Close
Return TM
End Sub