### Add Nodes (B4J Visual Designer)

An example of adding Nodes (Labels in this case) to a ScrollPane.
An empty B4J Visual Designer layout is used to create the Scrollpane InnerNode.
`Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private ScrollPane1 As ScrollPane
Private btnSetScrollPosition As Button
Private PrevLabel as Label
Private lblInfo As Label
End Sub`
`Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("Main")
MainForm.SetFormStyle("UTILITY")
MainForm.Title = "B4J HowTo Test ScrollPane"
MainForm.Show
AppInit
End Sub`
'Init controls, settings etc.
`Sub AppInit
CSSUtils.SetStyleProperty(lblInfo, "-fx-font-weight", "bold")
CSSUtils.SetStyleProperty(lblInfo, "-fx-font-size", 20)
'Set scrollpane properties
ScrollPane1.SetVScrollVisibility("ALWAYS")
'Load an empty layout. Ensure to set w and h to 0 and NOT to -1 else innernode height not set
ScrollPane1.LoadLayout("ScrollPane.bjl", 0, 0)
'Get the pane of the innernode
Dim n As Pane = ScrollPane1.InnerNode
'Add some nodes
For i = 0 To 100
Dim lbl As Label
lbl.Initialize("lbl")
lbl.Text = "Label " & i
lbl.Tag = i
n.AddNode(lbl, 5, i * 20, -1, -1)
Next
'Adjust the height of the innernode pane
n.PrefHeight = (i * 20) + 20
End Sub`
'Close the app - add any specifics here
`Sub AppClose
MainForm.Close
End Sub`
'Handle form closing via system close (top right X button)
`Sub MainForm_CloseRequest (EventData As Event)
AppClose
End Sub`
'Handle scrollview mouseclick = log the label text of the clicked label
`Sub lbl_MouseClicked (EventData As MouseEvent)
Dim lbl As Label = Sender
If PrevLabel.IsInitialized = True Then CSSUtils.SetStyleProperty(PrevLabel, "-fx-font-weight", "normal")
CSSUtils.SetStyleProperty(lbl, "-fx-font-weight", "bold")
lblInfo.Text = $"Clicked ${lbl.Text}"$
PrevLabel = lbl
End Sub`
'Scroll to a random position
`Sub btnSetScrollPosition_Action
Dim pos As Double = Rnd(0,100)
ScrollPane1.VPosition = pos * 0.01
lblInfo.Text = $"Scrolled to ${NumberFormat(Pos, 1,2)}%"$
'lblInfo.Text = $"Scrolled to ${NumberFormat(ScrollPane1.VPosition, 1,2)}"$
End Sub`

Changed: , Category: ScrollPane, File: T6C243M1769.htm, ID: 1769