B4J Question [B4X] [XUI] Scrolling Label, Scroll with short text

Revisable5987

Member
Licensed User
I understand that the Scrolling label is designed as such:
A custom view with a label that scrolls automatically when the text is wider than the label.

Is there anyway to have the text scroll when the label is wider than the text?
I've had a search but I couldn't see if anyone had already asked.

Thanks
 

Revisable5987

Member
Licensed User
Have you tried padding the text with spaces?
That was my initial thought but the text will be of varying sizes as it is fetched from a database.

I suppose I could add padding dependant of the length of text returned?
Although would this cause large amounts of blank scrolling if the window is made smaller by the user?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Just tried it out of curiosity, You can use this sub to set the required padding and remove ellipses (B4j only)

B4X:
Private Sub PadScrollingLabel(ScrollLabel As ScrollingLabel)
    Dim Lbl As B4XView = ScrollLabel.mBase.GetView(0).GetView(0).GetView(0)
    #if B4j
    Dim Jo As JavaObject = Lbl
    Jo.RunMethod("setEllipsisString",Array(""))
    #end if
    Dim CVS As B4XCanvas
    CVS.Initialize(MainForm.RootPane)
    Dim R As B4XRect = CVS.MeasureText(Lbl.Text,Lbl.Font)
    
    Do While R.Width < ScrollLabel.mBase.Width
        ScrollLabel.Text = ScrollLabel.Text & " "
        R = CVS.MeasureText(ScrollLabel.Text,Lbl.Font)
    Loop
    
End Sub

Usage:

B4X:
ScrollingLabel2.Text = "Test"
PadScrollingLabel(ScrollingLabel2)
 
Upvote 0
Top