### Sample ComboBox

Example (Code Snippets) of defining a ComboBox in a customized ToolBar.
Requires the JavaObject Library.
Define the ToolBar Object
`Sub Process_Globals
Private JavaObject_Toolbar As JavaObject
End Sub`
Define a ComboBox to be added to the ToolBar
' Add a combobox to the toolbar.
' Eventname - Unique eventname for the toolbar
' Items - List of items
' Tag - Unique tag used for the toolbar action
' Width - Set width. If -1 then width is set by the toolbar object
' BackgroundColor - Background color
' TextColor - Text color
' ToolTipText - Set the tooltip text
`Sub ToolBar_Combobox(EventName As String, Items As List, Tag As Object, Width As Double, BackgroundColor As Paint, TextColor As Paint, ToolTipText As String) As ComboBox
Dim cb As ComboBox
cb.Initialize(EventName)
cb.Tag = Tag
cb.Items.AddAll(Items)
cb.TooltipText = ToolTipText
If BackgroundColor.IsInitialized Then CSSUtils.SetBackgroundColor(cb, BackgroundColor)
If TextColor.IsInitialized Then CSSUtils.SetStyleProperty(cb, "-fx-text-fill", CSSUtils.ColorToHex(TextColor))
cb.Top = 0
cb.PrefHeight = 30
If Width <> -1 Then cb.PrefWidth = Width
If cb.Items.Size > 0 Then cb.SelectedIndex = 0
Return cb
End Sub`
Create the Toolbar using the ComboBox subroutine
Dim EventName As String = "Toolbar"
' Init the toolbar object
JavaObject_Editor_Toolbar_Styling.InitializeNewInstance("javafx.scene.control.ToolBar", Null)
' Create list of nodes to add to the toolbar - in this case only one item i.e. the combobox
Dim l As List
l.Initialize
' List of combobox items
Dim Items As List
Items.Initialize
Items.AddAll(Array("Item A", "Item B", "Item C")
Items.Sort(True)
l.Add(ToolBar_Combobox(EventName, Items, 1, -1, Null, Null, "List of items."))
' add more ... ensure to use unique tags!
'Add the list of toolbar nodes to the JavaObject
JavaObject_Editor_Toolbar_Styling.RunMethodJO("getItems", Null).RunMethod("addAll", Array(l))
'Add the toolbar JavaObject to the mainform with a height of 30.0
MainForm.Rootpane.AddNode(JavaObject_Editor_Toolbar_Styling, 0, 0, 400, 30)
Handle the toolbar event
`Sub Toolbar_Action
' Get the toolbar items to determine the combobox with the html tags
Dim l As List = JavaObject_Toolbar.RunMethod("getItems", Null)
For Each s As Object In l
' Combox found, check the tag of the combobox (see creation of the toolbar)
' The combobox Tag=1
If s Is ComboBox Then
Dim cb As ComboBox = s
If cb.Tag = 1 Then
' Do something with the selected combox value
cb.Value
End If
End If
Next
`

Changed: , Category: ToolBar, File: T6C270M2009.htm, ID: 2009