B4J Question [Solved] Add event handler for TextField from another class module

khaleel

Member
Licensed User
Longtime User
I have a class module that needs to add an event handler fro a textfield that is passed-in as a paramter
when the class is initialised.

I place a breakpoint in the sub TextField1_KeyPressed,but execution does not reach this sub
any ideas why is that so ?
and where can I find documentation about different kinds of events that I can catch for different type of nodes ?


Sub Class_Globals
Private fx As JFX
End Sub

Public Sub Initialize(tf As TextField)

Dim r As Reflector
r.Target = tf
r.AddEventHandler ("TextField1_KeyPressed", "javafx.scene.input.KeyEvent.KEY_PRESSED")



End Sub
Sub TextField1_KeyPressed(e As Event)

End Sub
 

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
i do it like this:

B4X:
    dim joTXT as javaobject = txt
    Dim event As Object = joTXT.CreateEventFromUI("javafx.event.EventHandler","keypressed", Null)

    joTXT.RunMethod("setOnKeyPressed", Array(event))

private Sub keypressed_Event (MethodName As String, Args() As Object) As Object
        CallSubDelayed2("yourModule","YourEventName" & "_keypressed",args(1))
End Sub
 
Upvote 0

khaleel

Member
Licensed User
Longtime User
Thank you Enrique,your solution works great !
I tried ti buy you some coffee but found that my cc was expired,sorry!
 
Upvote 0
Top