B4J Question [Solved] Add BBScrollingLabel to legacy form created in Scene Builder

bdunkleysmith

Active Member
Licensed User
Longtime User
I wish to make use of a BBScrollingLabel referred to here: [B4X] BBScrollingLabel - rich text scrolling label, however I want to place it in a form which is part of a legacy project where the form was created in Scene Builder.

If I add a label to the form with Id lblScroll via Scene Builder, then:

B4X:
Private lblScroll As BBScrollingLabel

not unexpectedly throws an error:

B4X:
display._show (java line: 587)
java.lang.ClassCastException: class b4j.example.bbscrollinglabel cannot be cast to class anywheresoftware.b4a.ObjectWrapper (b4j.example.bbscrollinglabel and anywheresoftware.b4a.ObjectWrapper are in unnamed module of loader 'app')
    at anywheresoftware.b4j.objects.FXMLBuilder.setNodeField(FXMLBuilder.java:157)
    at anywheresoftware.b4j.objects.FXMLBuilder.LoadLayout(FXMLBuilder.java:141)
    at anywheresoftware.b4j.objects.PaneWrapper.LoadLayout(PaneWrapper.java:96)
    at b4j.example.display._show(display.java:587)
    at b4j.example.main._appstart(main.java:225)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
    at java.base/java.lang.reflect.Method.invoke(Method.java:577)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
    at b4j.example.main.start(main.java:37)
    at javafx.graphics@18.0.1/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:847)
    at javafx.graphics@18.0.1/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484)
    at javafx.graphics@18.0.1/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    at javafx.graphics@18.0.1/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
    at javafx.graphics@18.0.1/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics@18.0.1/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics@18.0.1/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
    at java.base/java.lang.Thread.run(Thread.java:833)

Is there a way to overcome this problem, perhaps by adding a BBScrollingLabel programmatically to the existing form?
 
Solution
1681138515708.png


The max width was set to 600. Increase it in the designer to 2000.

Example of adding 5 views programmatically:
B4X:
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    TextEngine.Initialize(MainForm.RootPane)
    Dim s As String = $"[TextSize=72][b][u]BBScrollingLabel[/u][/b]: [color=red]Red[/color] [color=0xFF08B31F]Green[/color] [color=blue]Blue[/color]. More information: [url]https://www.b4x.com[/url]...............[/TextSize]"$
    Dim root As B4XView = MainForm.RootPane
    For i = 0 To 4
        Dim pnl As B4XView = xui.CreatePanel("")
        root.AddView(pnl, 10dip, 10dip + 110dip * i, root.Width - 20dip, 100dip)
        pnl.LoadLayout("Scroll")
        lblScroll.TextEngine = TextEngine
        lblScroll.Text = s
    Next
    MainForm.Show
End Sub

Erel

B4X founder
Staff member
Licensed User
Longtime User
 
Upvote 0

bdunkleysmith

Active Member
Licensed User
Longtime User
I have tried to use the method from the post referenced above in Post #2 however I do not see the scrolling text effect.

Attached is a simple project with a form containing a BBScrollingLabel and a second BBScrollingLabel added by code. It can be seen that the BBScrollingLabel embedded in the form displays scrolling text while the BBScrollingLabel added by code shows static text.

I'm obviously missing something simple. Any guidance would be appreciated.
 

Attachments

  • ScrollTest.zip
    3.3 KB · Views: 162
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1681138515708.png


The max width was set to 600. Increase it in the designer to 2000.

Example of adding 5 views programmatically:
B4X:
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    TextEngine.Initialize(MainForm.RootPane)
    Dim s As String = $"[TextSize=72][b][u]BBScrollingLabel[/u][/b]: [color=red]Red[/color] [color=0xFF08B31F]Green[/color] [color=blue]Blue[/color]. More information: [url]https://www.b4x.com[/url]...............[/TextSize]"$
    Dim root As B4XView = MainForm.RootPane
    For i = 0 To 4
        Dim pnl As B4XView = xui.CreatePanel("")
        root.AddView(pnl, 10dip, 10dip + 110dip * i, root.Width - 20dip, 100dip)
        pnl.LoadLayout("Scroll")
        lblScroll.TextEngine = TextEngine
        lblScroll.Text = s
    Next
    MainForm.Show
End Sub
 
Upvote 0
Solution
Top