B4J Question How to add BBLabel/BBcode by code?

xulihang

Active Member
Licensed User
Longtime User
I am trying to use BBLabel to show rich text.

I can add them by using the designer. But I need to add them by code. I didn't figure out how to do this.

I can add a pane which contains a BBLabel, but I can't get it by GetNode method.

B4X:
Dim pane As Pane
pane.Initialize("")
pane.LoadLayout("bblabel")
MainForm.RootPane.AddNode(pane,10,10,100,100)
Dim BBLabel1 As BBLabel=MainForm.RootPane.GetNode(0) 'error type not match
 

xulihang

Active Member
Licensed User
Longtime User
I come up with this after some study of the source code.
B4X:
Dim pane As Pane
pane.Initialize("")
pane.LoadLayout("bblabel")
Dim TextEngine As BCTextEngine
TextEngine.Initialize(pane)
MainForm.RootPane.AddNode(pane,10,10,100,100)
Dim n As Pane=pane.GetNode(0)
Dim BBLabel1 As BBLabel=n.Tag
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Tip:
- No reason to use the Pane type. B4XView is better.
- Never load a layout to a zero sized container .
B4X:
Dim panel As B4XView = xui.CreatePanel("")
MainForm.RootPane.AddNode(panel,10,10,100,100)
panel.LoadLayout("bblabel")
TextEngine.Initialize(pane)
If BBLabel1 is a global variable then it will hold a reference to the BBLabel that was created. Otherwise:
B4X:
Dim BBLabel1 As BBLabel = panel.GetView(0).Tag
 
Upvote 0
Top