B4J Question Extract information from mouse click eventdata - how to do?

Elby dev

Member
Licensed User
When I log the eventdata from a mouse click I can see the following object information:
(MouseEvent) MouseEvent [source = TableView@904d6b5[styleClass=table-view], target = Text[text="Shepparton", x=0.0, y=0.0, alignment=LEFT, origin=BASELINE, boundsType=LOGICAL_VERTICAL_CENTER, font=Font[name=System Regular, family=System, style=Regular, size=15.0], fontSmoothingType=LCD, fill=0xffffffff], eventType = MOUSE_CLICKED, consumed = false, x = 769.0, y = 282.0, z = 0.0, button = SECONDARY, pickResult = PickResult [node = Text[text="Shepparton", x=0.0, y=0.0, alignment=LEFT, origin=BASELINE, boundsType=LOGICAL_VERTICAL_CENTER, font=Font[name=System Regular, family=System, style=Regular, size=15.0], fontSmoothingType=LCD, fill=0xffffffff], point = Point3D [x = 63.0, y = -2.0, z = 0.0], distance = 1772.7241335952167]

I can see the the text or node with the string "Shepparton" This is what I need to extract into a variable. How can I do this? Please I had a look around but cannot find an answer.

I use a TBLViewAgents_MouseClicked (EventData As MouseEvent) this will show me all the cells data when I click onto it like the sample above. I just need to extract info from it.
Hope somebody can help Thanks
 

Elby dev

Member
Licensed User
Hi The Mouse events are ok they work fine. I am trying to extract the text information inside the eventdata returned from a click etc.
At the moment I extract it with the following snippet which is NOT the proper way. I am trying to find the correct way of extracting the text within like "Shepparton"
which is the information inside the tableview cell clicked on. The the extraction I do with a little string manipulation to get me by but is not the right way.
Dim index1 As Int
Dim index2 As Int
Dim s As String

If EventData.SecondaryButtonPressed = True Then
s = EventData 'This line I believe is not correct but it does sort of work to get to the event data
Log(s)
If s.Contains("target = Text[text=") Then
index1 = s.IndexOf(",")
index2 = s.IndexOf2(",",index1 + 1)
s = s.SubString2(index1 + 22,index2 - 1)
fx.Clipboard.SetString(s)
lblMsg.Text = s & " On Clipboard"
lblMsg.Visible = True
Sleep(1000)
lblMsg.Visible = False
End If
End If
Thanks
 
Upvote 0

Elby dev

Member
Licensed User
Thank you both for the replies. Thanks Erel for the JavaObject snippet. It is exactly what I needed to get to the various data inside 'EventData' works well.
It is an easy way for users to extract the various cell data from a table view and pushes it onto the system clipboard with a mouse click event.
 
Upvote 0

Elby dev

Member
Licensed User
Hi I have to ask, One small question just out of interest. Erel's code snippet initially did not work for me on a table view cell.
After logging the objects I found i had to change

B4X:
If GetType(target) = "javafx.scene.text.Text" Then
to
If GetType(target) = "com.sun.javafx.scene.control.LabeledText" Then
As that was returned from GetType.
Then it was OK.
Is this from a library or from the tableview component? Just curious.

Ps Sorry about the code tags, I put them in this time :)
 
Upvote 0
pickResult = PickResult [node = Text[text="Shepparton"

I know this is an old thread, I am trying to get the text out of the pickResult = PickResult [node = Text[text= in the mouseEvent but everything that I am doing is not getting the string after the text=. Do you know the way to extract the text?

Kind Regards
 
Upvote 0

Elby dev

Member
Licensed User
I know this is an old thread, I am trying to get the text out of the pickResult = PickResult [node = Text[text= in the mouseEvent but everything that I am doing is not getting the string after the text=. Do you know the way to extract the text?

Kind Regards
[/QUOTE]
Hi Christopher,
This is the sub routine I have to extract values from tableview cells. This should help you. Reg
B4X:
'Sub below pulls the clicked cell value and put's it on the clipboard
Sub tblViewPostCodes_MouseClicked (EventData As MouseEvent)
    If EventData.SecondaryButtonPressed = True Then
        Dim jo As JavaObject = EventData
        Dim target As JavaObject = jo.RunMethod("getTarget", Null)
        'Log(GetType(target))    'To see what the target actually is = com.sun.javafx.scene.control.LabeledText
        'If GetType(target) = "javafx.scene.text.Text" Then   'From Erels sample
        If GetType(target) = "com.sun.javafx.scene.control.LabeledText" Then   
            Dim s As String = target.RunMethod("getText", Null)                'This get's the text value from the clicked table cell.
                                                                                'If this is "getFont" then you get the font details of the cell etc etc
            'Log(s)
            If s.Length > 0 Then
                fx.Clipboard.SetString(s)
                lblMsg.Text = s & " On Clipboard"
                lblMsg.Visible = True
                Sleep(1000)
                lblMsg.Visible = False
            End If   
        End If
    End If
End Sub
 
Upvote 0
Top