B4J Question How to add TextArea MouseReleased Event?

xulihang

Active Member
Licensed User
Longtime User
Hi,

I want to get the selected text of a textarea after the selection is done.

There is no mousereleased event for textarea and I used javaobject to addevent. But I did not get it work.

Code is like this:

B4X:
Dim CJO As JavaObject = TextArea1
Dim O As Object = CJO.CreateEventFromUI("javafx.event.EventHandler","TextArea1_MouseReleased",Null)
CJO.RunMethod("setOnMouseReleased",Array(O))

B4X:
Sub TextArea1_MouseReleased_Event (MethodName As String, Args() As Object) As Object
   Log("released")
End Sub

What is the right way to do this?

Thanks.
 

stevel05

Expert
Licensed User
Longtime User
It appears that the MouseReleased event is being consumed before you can get it with the eventhandler. You can get it by adding an event filter which catches the event earlier in the chain.

B4X:
    Dim CJO As JavaObject = TextArea1
    Dim O As Object = CJO.CreateEventFromUI("javafx.event.EventHandler","TextArea1_MouseReleased",Null)
    Dim MouseEvent As JavaObject
    MouseEvent.InitializeStatic("javafx.scene.input.MouseEvent")
    CJO.RunMethod("addEventFilter",Array(MouseEvent.GetField("MOUSE_RELEASED"),O))

B4X:
Sub TextArea1_MouseReleased_Event (MethodName As String, Args() As Object) As Object
    Log("released")
End Sub

Although this will not catch selections made with the keyboard.

The TextArea has a selection property and a selectedText Property which you could listen to to capture all selection changes.
 
Last edited:
Upvote 0
Top