### MenuItem Style

Example changing the default style of a menuitem.
Menu JSON definition
The menubar menuitems JSON string must contain an unique tag per menuitem:
{Text: "_Save", Tag:"FileSave", EventName: "FileSave"},
Change the Style
The menuitems are collated in a global map. The menuitem to change is determined by its tag.
In a subroutine, the menuitem style is changed using the setStyle API menthod (requires the JavaObject library).
`Private Sub MenuItemBold(MenuTag As String)
Dim mi As MenuItem = MenuItems.Get(MenuTag)
If mi.IsInitialized Then
Dim joMI As JavaObject = mi
joMI.RunMethod("setStyle", Array("-fx-font-weight: bold;"))
End If
End Sub`
In the attached example, menu file > save is set to bold
MenuItemBold("FileSave")
Hints
If other menuitem types, like a checkmenuiten, then add or change the sub accordingly.
Other styles are also possible, like setting the font to red ("-fx-text-fill:red") etc.
Full Project Example
`Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private MenuBar1 As MenuBar
Private MenuItems As Map
End Sub`
`Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("Main")
MainForm.Show
MenuItems = MenuBar_Items(MenuBar1)
MenuItemBold("FileSave")
End Sub`
`Private Sub MenuItemBold(MenuTag As String)
Dim mi As MenuItem = MenuItems.Get(MenuTag)
If mi.IsInitialized Then
Dim joMI As JavaObject = mi
joMI.RunMethod("setStyle", Array("-fx-font-weight: bold;"))
End If
End Sub`
' Build the menubar items as map
`Public Sub MenuBar_Items(MnuBar As MenuBar) As Map
Dim menus As Map
menus.Initialize
CollectMenuItems(menus, MnuBar.Menus)
Return menus
End Sub`
' Collate the menu items as a list - used by MenuBar_Items
`Private Sub CollectMenuItems(Menus As Map, Items As List)
For Each mi As MenuItem In Items
If mi.Tag <> Null And mi.Tag <> "" Then Menus.Put(mi.Tag, mi)
If mi Is Menu Then
Dim mn As Menu = mi
CollectMenuItems(Menus, mn.MenuItems)
End If
Next
End Sub`

Changed: , Category: Menu, File: T6C220M1622.htm, ID: 1622