Wish B4XCanvas DrawText alignment

klaus

Expert
Licensed User
Longtime User
Hi Erel,
The B4XCanvas DrawText method alignment property is either "LEFT", "CENTER" or "RIGHT".
These properties look like Strings.
But, this works:
xcvsGraph.DrawText(txt, Graph.Left - 0.6 * Texts.ScaleTextHeight, y + 0.38 * Texts.ScaleTextHeight, Texts.ScaleFont, ID.Color, "LEFT")
but this doesn't, tested with B4J:
Private Alignment = "LEFT" As String
xcvsGraph.DrawText(txt, Graph.Left - 0.6 * Texts.ScaleTextHeight, y + 0.38 * Texts.ScaleTextHeight, Texts.ScaleFont, ID.Color, Alignment)

Error:
java.lang.ClassCastException: java.lang.String cannot be cast to javafx.scene.text.TextAlignment

Wish, as the properties are Strings couldn't these be converted into the corresponding object in the library.
Or am I missing something.

Thank you in advance.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This works fine here:
B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private xui As XUI
    Private Alignment = "RIGHT" As String
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.Show
    Dim c As B4XCanvas
    c.Initialize(MainForm.RootPane)
    c.DrawText("sdfsdf", 100, 100, xui.CreateDefaultFont(20), xui.Color_Red, Alignment)
End Sub
 
Top