### Drag and Drop

Example using Drag and Drop of Text into the TextArea at caret position
The form contains a TextArea view defined as node TextArea1 in the globals.
Code Snippet
`Sub Process_Globals
Private TextArea1 As TextArea
End Sub`
`Sub AppStart (Form1 As Form, Args() As String)
...
TextArea1_AddDropEvent
End Sub`
`Sub TextArea1_AddDropEvent
Dim joTA As JavaObject = TextArea1
Dim oTADO As Object = joTA.CreateEvent("javafx.event.EventHandler","TextAreaDragOver",False)
joTA.RunMethod("setOnDragOver",Array(oTADO))
Dim oTADD As Object = joTA.CreateEvent("javafx.event.EventHandler","TextAreaDragDropped",False)
joTA.RunMethod("setOnDragDropped",Array(oTADD))
End Sub`
' DragAndDrop: accept the transfer mode
`Private Sub TextAreaDragOver_Event(EventName As String,Args() As Object) As Object
Dim DnDEvent As Event = Args(0)
Dim DnDEventJO As JavaObject = Args(0)
Log(DnDEvent)
Dim joTM As JavaObject
joTM.InitializeStatic("javafx.scene.input.TransferMode")
' joTM.GetField("COPY_OR_MOVE")
DnDEventJO.RunMethod("acceptTransferModes", Array(joTM.GetField("ANY")))
DnDEvent.Consume
Return False
End Sub`
' DragAndDrop: handle dropping the string at caret position
`Private Sub TextAreaDragDropped_Event(EventName As String,Args() As Object) As Object
Dim DnDEvent As Event = Args(0)
Dim DnDEventJO As JavaObject = Args(0)
Log(DnDEvent)
Log(DnDEventJO)
Dim OK As Boolean = False
Dim joDragboard As JavaObject = DnDEventJO.RunMethod("getDragboard", Null)
If joDragboard.RunMethod("hasString", Null) Then
InsertText(TextArea1, joDragboard.RunMethod("getString", Null))
' TextArea1.Text = joDragboard.RunMethod("getString", Null)
OK = True
End If
DnDEventJO.RunMethod("setDropCompleted", Array(OK))
DnDEvent.Consume
Return False
End Sub`
' Insert text at the textarea caret position.
' TxtArea - TextArea
' Text - String to insert
' Example: InsertText(TextArea1, "Now = " & DateTime.Time(DateTime.Now))
`Public Sub InsertText(TxtArea As TextArea, Text As String)
Dim joTxtArea As JavaObject = TxtArea
Dim npos As Int = joTxtArea .RunMethod("getCaretPosition", Null)
If npos < 0 Then Return
joTxtArea.RunMethod("insertText", Array As Object(npos, Text))
TxtArea.RequestFocus
End Sub`

Changed: , Category: TextArea, File: T6C261M1924.htm, ID: 1924