You can add an event to capture the 'OnShowing" event
B4X:
Dim theMenu As JavaObject = theRealMenu ' this bit was missing
Dim e As Object = theMenu.CreateEvent("javafx.event.EventHandler","menuTitleClick",False)
theMenu.RunMethod("setOnShowing",Array(e)
...
Sub menuTitleClick_Event(MethodName As String, Args() As Object)
Log(Args(0))
End Sub
...
You can add an event to capture the 'OnShowing" event
B4X:
Dim theMenu As JavaObject
Dim e As Object = theMenu.CreateEvent("javafx.event.EventHandler","menuTitleClick",False)
theMenu.RunMethod("setOnShowing",Array(e)
...
Sub menuTitleClick_Event(MethodName As String, Args() As Object)
Log(Args(0))
End Sub
...
This is interesting for something I am working on but...
The first problem is that java wants the theMenu JavaObject to be initialized, but there is no "Initialize" method, instead there are 3 different Initialize... methods and I do not know which to use or how to set it...
Then I do not understand how to associate the JavaObject to a menu bar or a menu.
Assume that my menu is declared as follows:
B4X:
' create menu bar
mb.Initialize( "MenuBar" )
MainForm.RootPane.AddNode( mb, 0, 0, -1, -1 )
' Add top level File menu to menu bar
Dim FileMenu As Menu
FileMenu.Initialize( "File", "" )
mb.Menus.Add( FileMenu )
How do I detect the user clicking on "File" for instance?
Sorry, had a brain phart and forgot to add the menu to the javaobject dim line.
B4X:
' after you have defined FileMenu
Dim theMenu As JavaObject = FileMenu
Dim e As Object = theMenu.CreateEvent("javafx.event.EventHandler","menuTitleClick",False)
theMenu.RunMethod("setOnShowing",Array(e)
...
Sub menuTitleClick_Event(MethodName As String, Args() As Object)
Log(Args(0))
End Sub
...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.