B4J Question detect menu click event

Discussion in 'B4J Questions' started by le_toubib, Jun 21, 2019.

  1. le_toubib

    le_toubib Active Member Licensed User

    hi all
    is there a way to detect the menu_Click event ???
    not the menubar
    not the menu items ..
    just the title itself.
     
  2. Daestrum

    Daestrum Well-Known Member Licensed User

    You can add an event to capture the 'OnShowing" event

    Code:
    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: Jun 21, 2019
  3. Didier9

    Didier9 Active Member Licensed User

    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:
    Code:
    ' create menu bar
    mb.Initialize( "MenuBar" )
    MainForm.RootPane.AddNode( mb, 
    00, -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?
     
  4. Daestrum

    Daestrum Well-Known Member Licensed User

    Sorry, had a brain phart and forgot to add the menu to the javaobject dim line.
    Code:
    ' 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
    ...
     
    Didier9 likes this.
Loading...
  1. 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.
    Dismiss Notice