B4J Question B4J why does jo.RunMethod("setTextAlignment", Array("RIGHT")) fail?

johnmie

Member
Licensed User
B4X:
lang="b4x"
For i = 1 To maxCol
        Dim L As B4XView = Labels.Get(i).As(B4XView)
        L.Text=Txt(nLine+m) 'Labels.Get(i).As(B4XView).Text
        L.Height = -1
        If i = 2 Then 'format of column 2
            Dim jo As JavaObject = L
            jo.RunMethod("setTextAlignment", Array("RIGHT"))
            L.font = fx.CreateFont("", 14, True, False)
            L.TextColor = xui.Color_Red
        End If
        m=m+1
    Next

Using the above code I get this result in BBCODEVIEW under B4J:
BBcodeTable.PNG

Where text in column 2 should be bold, red and right aligned, but this seemd works only to work when the underlying label is multiline.
Why does it not work when the text fits on a single line? Does this have to do with Array("RIGHT")?

Your help will be greatly apreciated. Thank you.
 

drgottjr

Well-Known Member
Licensed User
Longtime User
take a look at this link
i think you need vertical and horizontal alignment, not just horizontal. (although i would have expected a signature mismatch when you run the method.)
 
Upvote 1

johnmie

Member
Licensed User
My table is not a conventional table, but a workaround for a table in BBCodeView which normally allows you only to set MaxWidth and Alignment.
If a text is longer than the Maxwidth then all cells thereafter are chased to the right and the table no longer looks like a table with neatly aligned columns.
This is why I place the texts first into labels and then add these as snapshots and views to the BBCode.

There is probably a more elegant way to achieve this, but my programming skills and command of Java have limits (obviously).
 
Upvote 0

johnmie

Member
Licensed User
How to implement vertical & horizontal text-alignment in a Javaobject?
jo.RunMethod"setTextAlignment", Array("TOP","RIGHT") does not work and
jo.RunMethod("setTextBaseline", Array("BASELINE")) does not work

where do I find a list of all available jo.RunMethods?
 
Upvote 0

johnmie

Member
Licensed User
Got it, finally!
it requires both:
L.SetTextAlignment("TOP","RIGHT")
jo.RunMethod("setTextAlignment", Array("RIGHT"))

thank you all for your help,
john m.
 
Upvote 0
Top