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

Didier9

Well-Known Member
Licensed User
Longtime 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:
B4X:
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.
    MainForm.Show
    
    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 -):
B4X:
    ' 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?
TIA
 

Daestrum

Expert
Licensed User
Longtime User
Try
B4X:
 Dim s As JavaObject
 s.InitializeNewInstance("javafx.scene.control.SeparatorMenuItem",Null)
 SettingsMenu.MenuItems.Add( s )
 
Upvote 0
Top