Private bmVariable As JavaObject
bmVariable.InitializeNewInstance("javafx.scene.control.MenuButton",Array As Object("V"))
apMain.AddNode(bmVariable,57,10,40,25)
Sub Class_Globals
Private fx As JFX
Private bmVariable As JavaObject
end sub
Public Sub Initialize()
'Menu Button 1
bmVariable.InitializeNewInstance("javafx.scene.control.MenuButton",Array As Object("V"))
AddMenuItem("Menu Item 1")
end sub
Private Sub AddMenuItem(MenuText As String)
Private TheMenuItem As MenuItem
TheMenuItem.Initialize(MenuText,"miTA_Variables")
Dim miJO As JavaObject = TheMenuItem
bmVariable.RunMethodJO("getItems", Null).RunMethod("add", Array(miJO))
End Sub
Sub miTA_Variables_Action
Private meit As MenuItem = Sender
Log("Menu Item: " & meit.Text)
End Sub
Add menu items in the Form Designer. First add a "MenuBar" view - then find "Menu Items" at the bottom of its Properties list and click on the ellipsis ". . .". Add the menu items as a JSON object like this .... . . a problem with adding menu items and the event name.
[
{Text: "File", Children:
[
"New", "Open ...", "Save", "Save As ...",
"-",
"Exit"
]
},
{Text: "Help", Children:
[ "Show help ..."
]
}
]
Sub mnuMain_Action
Dim item As MenuItem = Sender
If (item.Text.EqualsIgnoreCase("open ...")) Then
openScript
previewScript
End If
If (item.Text.EqualsIgnoreCase("save")) Then saveScript(False)
If (item.Text.EqualsIgnoreCase("save as ...")) Then saveScript(True)
If (item.Text.EqualsIgnoreCase("exit")) Then MainForm.Close
If (item.Text.EqualsIgnoreCase("show help ...")) Then showHelp
End Sub
Dim miJO As JavaObject
miJO.InitializeNewInstance("javafx.scene.control.MenuItem", Array As Object(MenuText))
bmVariable.RunMethodJO("getItems", Null).RunMethod("add", Array(miJO))
miJO.RunMethod("setOnAction", Array("miTA_Variables"))
Private Sub AddMenuItem(MenuText As String)
Dim miJO As JavaObject
miJO.InitializeNewInstance("javafx.scene.control.MenuItem", Array As Object(MenuText))
Dim mieJO As Object = miJO.CreateEventFromUI("javafx.event.EventHandler", "miTA_Variables_Action", Null)
miJO.RunMethod("setOnAction", Array(mieJO))
bmVariable.RunMethodJO("getItems", Null).RunMethod("add", Array(miJO))
End Sub
Sub miTA_Variables_Action
Private meit As MenuItem = Sender
Log("Menu Item: " & meit.Text)
End Sub
What's the benefits all those Java object run method compared to the b4j menu properties?
Menu has only one event to which the clicked item called is passed. Items are added, either by code or in the designer, by passing a json string to it...
I really don't understand why it's so troublesome to you.
Have you done a simple search about menu view?
One result that will surely enlighten you.
Thread 'Designer Menu Items' https://www.b4x.com/android/forum/threads/designer-menu-items.56602/
Other results are surely worth reading...
Of course menus and menu buttons are supported in B4J. Where are you trying to add this menu button? Is it not on a menubar?I'm adding a "Menubutton" to which I don't see any support for from B4J
Just browse the links I posted, all is there!!!I'm adding a "Menubutton" to which I don't see any support for from B4J. So I have to add it through code, I'm Just stuck now on setting the event name for menu item so when someone clicks an item I can do what I need to do..
So it's NOT a menubar...I'm adding a "Menubutton" ....
Of course menus and menu buttons are supported in B4J. Where are you trying to add this menu button? Is it not on a menubar?
So it's NOT a menubar...
Menu button has been wrapped into b4j very recently...
Thread '[B4j] MenuButton' https://www.b4x.com/android/forum/threads/b4j-menubutton.151950/
Using the search takes you a lot less time than reinventing something that already exists
Again... don't reinvent the wheel, @stevel05 created the menubutton lib exactly for that special case were what you need is just a menubutton and not a menubar...you can't declare a "menubutton" (at lease in the version of b4j I have. 9.30). I am adding to a Pane in a certain location. In javaFX Scene Builder 2.0 you can add anywhere. not adding to any menu bar.
I am able to add menubutton with no problem, the probem I am having to giving an event name so that I can process when user clicks a menu item.
Again... don't reinvent the wheel, @stevel05 created the menubutton lib exactly for that special case were what you need is just a menubutton and not a menubar...
The link is in that post you just quoted
Private TheMenuItem As MenuItem
TheMenuItem.Initialize(MenuText,"miTA_Variables")
Sub miTA_Variables_Action
Private meit As MenuItem = Sender
fx.Clipboard.SetString(meit.Text)
Log("Menu Item: " & meit.Text)
End Sub
Private Sub AddMenuItem(MenuText As String)
Private TheMenuItem As MenuItem
TheMenuItem.Initialize(MenuText,"miTA_Variables")
Dim miJO As JavaObject = TheMenuItem
bmVariable.RunMethodJO("getItems", Null).RunMethod("add", Array(miJO))
End Sub
Sub miTA_Variables_Action
Private meit As MenuItem = Sender
fx.Clipboard.SetString(meit.Text)
Log("Menu Item: " & meit.Text)
End Sub
Sub Class_Globals
Private fx As JFX
Private bmVariable As JavaObject
end sub
Public Sub Initialize()
'Menu Button 1
bmVariable.InitializeNewInstance("javafx.scene.control.MenuButton",Array As Object("V"))
AddMenuItem("Menu Item 1")
end sub
Private Sub AddMenuItem(MenuText As String)
Private TheMenuItem As MenuItem
TheMenuItem.Initialize(MenuText,"miTA_Variables")
Dim miJO As JavaObject = TheMenuItem
bmVariable.RunMethodJO("getItems", Null).RunMethod("add", Array(miJO))
End Sub
Sub miTA_Variables_Action
Private meit As MenuItem = Sender
Log("Menu Item: " & meit.Text)
End Sub
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?