### Change Color TreeItems

Change the color of the TreeItems dynamically. Requires the JavaObjects and CSSUtils library.
Background Color All Cells
'Set the background color of all cells.
'Example: SetTreeCellsBackgroundColor(TreeView1, fx.colors.yellow)
`Sub SetTreeCellsBackgroundColor(tv As TreeView, clr As Paint)
Dim joTV As JavaObject = tv
'Get all treecells
Dim joTCL As JavaObject = joTV.RunMethodJo("lookupAll", Array(".tree-cell"))
'Add those to an arraylist
Dim joAL As JavaObject
joAL.InitializeNewInstance("java.util.ArrayList", Array(joTCL))
'Create a List
Dim l As List = joAL
'Set the color of the treecells
For i = 0 To l.size - 1
CSSUtils.SetBackgroundColor(l.Get(i), clr)
'CSSUtils.SetStyleProperty(l.Get(i), "-fx-text-fill", "red")
Next
End Sub`
Text Color All Cells
'Set the text color of all cells.
'Example: SetTreeCellsTextColor(TreeView1, fx.colors.yellow)
`Sub SetTreeCellsTextColor(tv As TreeView, clr As String)
Dim joTV As JavaObject = tv
'Get all treecells
Dim joTCL As JavaObject = joTV.RunMethodJo("lookupAll", Array(".tree-cell"))
'Add those to an arraylist
Dim joAL As JavaObject
joAL.InitializeNewInstance("java.util.ArrayList", Array(joTCL))
'Create a List
Dim l As List = joAL
'Set the color of the treecells
For i = 0 To l.size - 1
CSSUtils.SetStyleProperty(l.Get(i), "-fx-text-fill", clr)
Next
End Sub`
Background Color Cells depending criteria
'Set the background color of a treeview cell depending its value.
'Note: Ensure to expand all items and use subdelayed after treeview been build
'Example: CallSubDelayed3(Me, "SetTreeCellsBackgroundColor2", TreeView1, 20)
`Sub SetTreeCellsBackgroundColor2(tv As TreeView, threshold As Int) 'ignore
Dim joTV As JavaObject = tv
'Get all treecells
Dim joTCL As JavaObject = joTV.RunMethodJo("lookupAll", Array(".tree-cell"))
'Add those to an arraylist
Dim joAL As JavaObject
joAL.InitializeNewInstance("java.util.ArrayList", Array(joTCL))
'Create a List
Dim l As List = joAL
'Set the color of the treecells
For i = 0 To l.size - 1
'Get the treecell
Dim joIP As JavaObject = l.Get(i)
'Get the treeitem belonging to the treecell
Dim ti As TreeItem = joIP.RunMethod("getTreeItem", Null)
'Check if treeitem is initialized and a number - f.e. if root is visible then not a number
If ti.IsInitialized And IsNumber(ti.Text) Then
'Set the cell color depending threshold
If ti.Text < threshold Then
CSSUtils.SetBackgroundColor(l.Get(i), fx.Colors.green)
Else
CSSUtils.SetBackgroundColor(l.Get(i), fx.Colors.red)
End If
End If
Next
End Sub`

Changed: , Category: TreeView, File: T6C272M2016.htm, ID: 2016