B4J Library jDragAndDrop library

jDragAndDrop library exposes the JavaFX drag and drop capability to B4J.

Drag and Drop will work within a B4J JavaFX application and between B4J JavaFXapplications - try running two copies of the demo and drag and drop between them. It will not work with non JavaFX applications and and also probably not with non B4J JavaFX applications because it deliberately exposes a simplified subset of the full drag and drop capabilities to make it easy to understand and use. Nevertheless you can pass quite complicated objects, not just primitives, as long as the objects are serializable.

Actually you can drop things from native programs and accept them as an Object but you would need to use JavaObject or Reflection to play with them.

EDIT :- Version 1.1 now posted. See post #3 for details.
 

Attachments

  • jDragAndDropDemo1.1.zip
    13.1 KB · Views: 1,420
Last edited:

agraham

Expert
Licensed User
Longtime User
Version 1.1 now posted with some, mainly invisible internal changes. DataIds are no longer case-insensitive and you can pass more than one DataId/DataObject pair in a single drag and drop. This is because after posting version 1.0 I was playing with it and found that I could accept drag and drop from external programs. The demo shows getting a file list dragged from Windows Explorer. Try it!
 

stevel05

Expert
Licensed User
Longtime User
Andrew,

I've just downloaded the attachment, the demo is drag and drop text. I there another one?

Steve
 

agraham

Expert
Licensed User
Longtime User
Sorry Steve but I don't understand the question. I've downloaded it and the demo looks OK. It shows dragging and dropping an Object array containing Strings and a Byte array within the demo, or between two running copies of the demo. If you select one or more files in Windows Explorer and drop them on the demo it will show you the file list. Note that output is to the Log pane.
 

stevel05

Expert
Licensed User
Longtime User
OK Thanks Andrew, I've got it now, I was taking the prompts literally, and didn't try the latter
 

Mieke

New Member
Licensed User
Longtime User
Hi Agraham, thank you for this lib.
Is it possible to drag from one tableview and drop on another tableview?
 

LucaMs

Expert
Licensed User
Longtime User
If I have not misunderstood, this method has a major drawback: it is necessary to know in advance the destination.

I have a number of listview and would like to be able to drag an item from one of them to another:
any suggestions?

(I could use x, y, but it all becomes complicated, especially if the container is resized)
 

Douglas Farias

Expert
Licensed User
Longtime User
how can i make a list of droped itens? DragDropped
the Log(e.GetDataObjectForId("text/uri-list")) returns only a string with all files and not a array or list
 

Tirs

Member
Licensed User
Longtime User
It's a pity it cannot accept dropped files from outside JavaFX. I would like to create an application where the user can open a file just by drag-and-dropping it from the Windows desktop to the application window (or an area of it). Is there any way to do it, be it with jDragAndDrop or without it?

Thanks in advance!
 

Tirs

Member
Licensed User
Longtime User
Well, I found a post by Erel saying that drag and drop will be implemented "in the future", but the post is from 2013. Any news since then?
 

jmon

Well-Known Member
Licensed User
Longtime User
It's a pity it cannot accept dropped files from outside JavaFX. I would like to create an application where the user can open a file just by drag-and-dropping it from the Windows desktop to the application window (or an area of it). Is there any way to do it, be it with jDragAndDrop or without it?

Thanks in advance!
In the example provided by Agraham, it shows how to receive links dropped from windows desktop:

B4X:
Sub Drop_DragOver(e As DragEvent)
    'Check the data id before accepting:
    Dim Links() As Object = Array As String(e.GetDataObjectForId("text/uri-list"))   
    If Links.Length > 0 Then e.AcceptTransferMode("MOVE")
End Sub

Private Sub Drop_DragDropped(e As DragEvent)
    Dim TextLinks As String = e.GetDataObjectForId("text/uri-list")
    Dim Links() As String = Regex.Split("\r\n", TextLinks)   
   
    If Links.Length > 0 Then
        For Each Link As String In Links               
            'your code here           
        Next

        e.SetDropCompleted(True)
        Return
    End If
End Sub
 

jmon

Well-Known Member
Licensed User
Longtime User

jmon

Well-Known Member
Licensed User
Longtime User
Would it be possible to add the DRAG_ENTERED_TARGET and DRAG_EXITED_TARGET events...
Nevermind, I noticed that I misunderstood the idea or the _Target events, so your library is already perfect as is!
Thanks.
 

Nokia

Active Member
Licensed User
Longtime User
In the example provided by Agraham, it shows how to receive links dropped from windows desktop:

B4X:
Sub Drop_DragOver(e As DragEvent)
    'Check the data id before accepting:
    Dim Links() As Object = Array As String(e.GetDataObjectForId("text/uri-list"))  
    If Links.Length > 0 Then e.AcceptTransferMode("MOVE")
End Sub

Private Sub Drop_DragDropped(e As DragEvent)
    Dim TextLinks As String = e.GetDataObjectForId("text/uri-list")
    Dim Links() As String = Regex.Split("\r\n", TextLinks)  
  
    If Links.Length > 0 Then
        For Each Link As String In Links              
            'your code here          
        Next

        e.SetDropCompleted(True)
        Return
    End If
End Sub

nice peace of code here, I was able to get this to work for windows how ever if I try to use on linux I get an about of bounds -2 error, same goes for if I try to drag and drop from outlook.

and anybody used this on Linux?
 
Top