### Sample 4

Sample to create a toolbar with
[BUTTON][BUTTON][TEXTFIELD][LABEL][BUTTON]
`Sub Process_Globals
Private fx As JFX
Private MainForm As Form
'Define the toolbar JavaObject
Private joToolbar As JavaObject
Private tbButton1 As Button
Private tbButton2 As Button
Private tbTextField1 As TextField
Private tbLabel1 As Label
Private tbButton3 As Button
End Sub`
`Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.SetFormStyle("UTILITY")
MainForm.RootPane.LoadLayout("Main")
MainForm.Title = "B4J HowTo Toolbar v20160608"
MainForm.Show
CreateToolBar
End Sub`
'Handle resizing of the mainform which adjusts the width of the toolbar object
`Sub MainForm_Resize (Width As Double, Height As Double)
joToolbar.RunMethod("setPrefWidth", Array(Width))
End Sub`
`Sub CreateToolBar
joToolbar.InitializeNewInstance("javafx.scene.control.ToolBar", Null)
tbButton1.Initialize("tbButton1"):tbButton1.Text="Button 1":tbButton1.TextColor=fx.Colors.Red
tbButton2.Initialize("tbButton2"):tbButton2.Text="Button 2":tbButton2.TextColor=fx.Colors.Blue
tbTextField1.Initialize("tbTextField1")
tbTextField1.TooltipText = "Enter text."
tbTextField1.PromptText = "Enter Text"
tbLabel1.Initialize("tbLabel1")
tbLabel1.Text = "Toolbar Label"
tbButton3.Initialize("tbButton3"):tbButton3.Text="About":tbButton3.TextColor=fx.Colors.Yellow
'Add the views to the toolbar
joToolbar.RunMethodJO("getItems", Null).runMethod("add", Array(tbButton1))
joToolbar.RunMethodJO("getItems", Null).runMethod("add", Array(tbButton2))
joToolbar.RunMethodJO("getItems", Null).runMethod("add", Array(tbTextField1))
joToolbar.RunMethodJO("getItems", Null).runMethod("add", Array(tbLabel1))
joToolbar.RunMethodJO("getItems", Null).runMethod("add", Array(tbButton3))
joToolbar.RunMethod("setStyle", Array("-fx-background-color: lightgrey;"))
'Add the toolbar
MainForm.RootPane.AddNode(joToolbar, 0, 0, MainForm.width, 50)
End Sub`
`Sub tbButton1_Action
Log("Toolbar Button1 clicked")
fx.Msgbox2(MainForm,"Toolbar Button 1 clicked", "Information", "OK", "", "", fx.MSGBOX_INFORMATION)
End Sub`
`Sub tbButton2_Action
Log("Toolbar Button2 clicked")
fx.Msgbox2(MainForm,"Toolbar Button 2 clicked", "Warning", "OK", "", "", fx.MSGBOX_WARNING)
End Sub`
`Sub tbButton3_Action
fx.Msgbox2(MainForm,MainForm.title, "About", "OK", "", "", fx.MSGBOX_INFORMATION)
End Sub`
Additional Subs to Control Button Enabling
'Enable or disable a button based on its id
'Example `
'EnableButton("Button1", False)
'`
`Sub EnableButton(Id As String, Enabled As Boolean)
Dim ButtonList As List = joToolbar.RunMethodJO("getItems", Null)
For Each n As Node In ButtonList
If n Is Button Then
Dim btn As Button = n
If btn.Id.EqualsIgnoreCase(Id) Then btn.Enabled = Enabled
End If
Next
End Sub`
'Enable or disable a buttons
'Example `
'Dim Btns() As Button = Array As Button(tbButton1,tbButton2)
'EnableButtons(Btns, False)
'`
`Sub EnableButtons(Btns() As Button, Enabled As Boolean)
Dim ButtonList As List = joToolbar.RunMethodJO("getItems", Null)
For Each n As Node In ButtonList
If n Is Button Then
Dim Btn As Button = n
For Each b As Button In Btns
If b = Btn Then Btn.Enabled = Enabled
Next
End If
Next
End Sub`

Changed: , Category: ToolBar, File: T6C270M2008.htm, ID: 2008