B4J Question TextArea_SelectionChanged Event?

Discussion in 'B4J Questions' started by xulihang, Sep 26, 2018.

  1. xulihang

    xulihang Active Member Licensed User


    The textarea control has not selectionchanged event. I have tried to implement this event using jreflection. I set the property to selectionProperty and can get the indexrange in the changed event.

    I am not familiar with reflection and javafx. Am I doing it right?

    The code I use:

    Sub addSelectionChangedEvent(textarea1 As TextArea,eventName As String)
    Dim Obj As Reflector
        Obj.Target = textarea1
    End Sub

    Sub sourceTextAreaSelection_changed(old As Object, new As Object)
    Dim ta As TextArea
    Dim indexString As String
    Dim selectionStart,selectionEnd As Int
    If selectionEnd<>selectionStart Then
    End If
    End Sub
    I also come across the RaisesSynchronousEvents error. The app does not crash. I add the code below to avoid the error log.

    #RaisesSynchronousEvents: SubThatCanRaiseEvent
    Last edited: Sep 26, 2018
  2. stevel05

    stevel05 Expert Licensed User

    I would be tempted to use JavaObject, it is a little more work to set up the listener but by using CreateEventFromUI it avoids the RaisedSynchronousEvent error.

    Also, once you have the Textarea in the callback, you can access the selected text from the Text area directly. This will work with either option.

    Sub addSelectionChangedEvent(textarea1 As TextArea,eventName As String)
    Dim JO As JavaObject = textarea1
    Dim Prop As JavaObject = JO.RunMethod("selectionProperty",Null)
    Dim O As Object = JO.CreateEventFromUI("javafx.beans.value.ChangeListener","SelectionChanged",Null)
    End Sub

    Private Sub SelectionChanged_Event (MethodName As String, Args() As Object)
    Dim Ta As TextArea = Sender
    End Sub
    Erel, xulihang and Daestrum like this.
  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