B4J Question detect menu click event

le_toubib

Active Member
Licensed User
Longtime User
hi all
is there a way to detect the menu_Click event ???
not the menubar
not the menu items ..
just the title itself.
 

Daestrum

Well-Known Member
Licensed User
Longtime User
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
...
 
Last edited:
Upvote 0

Didier9

Well-Known Member
Licensed User
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?
 
Upvote 0

Daestrum

Well-Known Member
Licensed User
Longtime User
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
...
 
Upvote 0
Top