### Change Button Icon dynamically

To change the icon of a button dynamically, two options shared.
Library CSSUtils
Select CSSUtils in the B4J IDE Library Manager.
Set button btnAdd background image "list-add.png".
The icon file "list-add.png" is located in the project files folder (DirAssets) and added to the B4J IDE Files Manager.
Dim btnAdd As Button
CSSUtils.SetBackgroundImage(btnAdd, File.DirAssets, "list-add.png")
Library JavaObject
Ensure to check the Library JavaObject from the B4J IDE Libraries Manager.
Ensure the icon is added to the B4J IDE Files Manager.
Reference: http://docs.oracle.com/javafx/2/api/javafx/scene/control/Button.html
Get Graphic: http://docs.oracle.com/javafx/2/api/javafx/scene/control/Labeled.html#getGraphic()
Example
`Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private imgButton As ImageView
Private btnTest As Button
Private btnChangeIcon As Button
End Sub`
`Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("Main")
MainForm.Show
End Sub`
' Change the icon of a button dynamically
' Ensure the icon is added to the ITE Files tab
`Sub btnChangeIcon_Action
Dim btnJO As JavaObject = btnTest
imgButton = btnJO.RunMethod("getGraphic", Null)
imgButton.SetImage(fx.LoadImage(File.DirAssets, "Icon2.png"))
End Sub`

Changed: , Category: Buttons, File: T6C167M1226.htm, ID: 1226