B4J Question How to insert a separator in B4J MenuBar [solved]


Active Member
Licensed User
in this post: https://www.b4x.com/android/forum/threads/designer-menu-items.56602/#content Erel indicates
Use a simple string item with the value of "-" to create a separator.
I have not managed to make this work. Tried this:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Dim mb As MenuBar
End Sub ' Process_Globals

Sub AppStart( Form1 As Form, Args() As String )
    MainForm = Form1
    MainForm.RootPane.LoadLayout( "Main" ) 'Load the layout file.
    mb.Initialize( "" )
    MainForm.RootPane.AddNode( mb, 0, 0, -1, -1 )

    ' Add Settings menu to menu bar
    Dim SettingsMenu As Menu
    SettingsMenu.Initialize( "Settings", "" )
    mb.Menus.Add( SettingsMenu )
    ' Add Serial Ports submenu to Settings menu
    Dim SerialPort As Menu
    SerialPort.Initialize( "Ports", "" )
    SettingsMenu.MenuItems.Add( SerialPort )
    ' add Baud Rates
    Dim mnBaudrates As Menu
    mnBaudrates.Initialize( "Baudrates", "" )
    SettingsMenu.MenuItems.Add( mnBaudrates )
    ' add separator
    Dim s As String = "-"
    SettingsMenu.MenuItems.Add( s )
    ' add COM TimeOut
    Dim m As MenuItem
    m.Initialize( "COM Time Out", "mCOMTimeOut" )
    SettingsMenu.MenuItems.Add( m )

End Sub
which crashes, and this (with varying number of -):
    ' add separator
    Dim m As MenuItem
    m.Initialize( "-", "" )
    SettingsMenu.MenuItems.Add( m )
which does not crash but does not produce a normal separator.

Could I have an example of what to insert into the menu structure to create a separator?


Well-Known Member
Licensed User
 Dim s As JavaObject
 SettingsMenu.MenuItems.Add( s )