B4J Question Form Click Event

mangojack

Expert
Licensed User
Longtime User
Ihave Read this post Here ... https://www.b4x.com/android/forum/threads/form-click.62380/#post-394245

but still cannot get a Form_Click event to work.

it is a B4XPages Project and in the main form / page I have the following
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("Main")
    
    Dim Form1 As Form
    Form1.Initialize("Form1" , 1600, 900)          'introduced to set Event Name ...
    Form1 = B4XPages.GetNativeParent(Me)
'.......................

Sub Form1_MouseClicked (EventData As MouseEvent)
    Log("Click")
End Sub

I have loaded the -MouseClicked Event from the type AnchorPane.

Thanks , Regards
 

stevel05

Expert
Licensed User
Longtime User
Your code:

B4X:
  Dim Form1 As Form
  Form1.Initialize("Form1" , 1600, 900)          'introduced to set Event Name ...
  Form1 = B4XPages.GetNativeParent(Me)

Is redundant, as the assignment of the parent form will overwrite the initialized form.

It will work in The Main module if you do:
B4X:
Private Sub MainForm_MouseClicked (EventData As MouseEvent)
    Log("MF Clicked")
End Sub

But this is not what you want.

The Form (Javafx Stage) does not support the MouseClicked events as explained in the post you linked, but you can add a listener to the Root of the B4xPage:

B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
  
    Dim O As Object = Root.As(JavaObject).CreateEventFromUI("javafx.event.EventHandler","RootClick",Null)
    Root.As(JavaObject).RunMethod("setOnMouseClicked",Array(O))

End Sub

Private Sub RootClick_Event (MethodName As String, Args() As Object)
    Dim Event As MouseEvent = Args(0)
    Log(Event.PrimaryButtonPressed)
    Log("Root Clicked")
End Sub
 
Last edited:
Upvote 0

mangojack

Expert
Licensed User
Longtime User

Thankyou for the solution and great explanation , it certainly works but has raised another issue.

Basically , clicking on a Pane displays another Pane containing menu Labels.

The thinking was if the Menu is Visible, clicking elswhere on the Form, hides the MenuPane.

Unfortunately, the Menu Pane Click attempts to show , but the Root Click_Event immediately hides it.

I tried consuming the Click in the Menu Pane , but no show.

Any advice / solution would be welcome.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
There can be problems consuming events under some circumstances, can you show the code you are using to call and show the menu? Or better still zip and post the project or a small example showing the issue so I can take a look?
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
There can be problems consuming events under some circumstances, can you show the code you are using to call and show the menu? Or better still zip and post the project or a small example showing the issue so I can take a look?

It is fairly basic .. Clicking Pane1 shows Pane2. (Visible = True)
Clicking on the form hides Pane2(Visible = False)

But for what its worth , I think I might simplify this by showing/hiding Pane 2 all in the Pane1_Clicks...

B4X:
Private Sub pnlImgProfile_MouseClicked (EventData As MouseEvent)
	If pnlMenu.Visible Then
		HideMenu
	Else
		pnlMenu.Visible = True
		pnlMenu.SetLayoutAnimated(200, 320, 3, 190, 150)	
	End If
End Sub


Again Thankyou
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
If that is working as you want it, then great.

I have a minimal wrap of the Javafx popup window that handles the autohiding if that would help.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…