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,309
Last edited:

jmon

Well-Known Member
Licensed User
Longtime User
I get an about of bounds -2 error
Not so sure why, but can you try with this code, I fixed an error:
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 Object = Array As String(e.GetDataObjectForId("text/uri-list"))
    For Each TextLink As String In TextLinks
        Dim Links() As String = Regex.Split("\r\n", TextLink)
    
        If Links.Length > 0 Then
            For Each Link As String In Links            
                'your code here   
                Log(Link)   
            Next

            e.SetDropCompleted(True)
            Return
        End If
    Next  
End Sub

[edit] What are you trying to drag-drop? This code works with a list of files only
 

Nokia

Active Member
Licensed User
Longtime User
Not so sure why, but can you try with this code, I fixed an error:

[edit] What are you trying to drag-drop? This code works with a list of files only


just files.. I have the code blocking folders I am trying this with simple text files.. works great on windows,, but linux I get the out of bounds -2 error..

have not tried OS X yet..
 

Nokia

Active Member
Licensed User
Longtime User
Not so sure why, but can you try with this code, I fixed an error:
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 Object = Array As String(e.GetDataObjectForId("text/uri-list"))
    For Each TextLink As String In TextLinks
        Dim Links() As String = Regex.Split("\r\n", TextLink)
   
        If Links.Length > 0 Then
            For Each Link As String In Links           
                'your code here  
                Log(Link)  
            Next

            e.SetDropCompleted(True)
            Return
        End If
    Next 
End Sub

[edit] What are you trying to drag-drop? This code works with a list of files only


I just seen that you posted an update.. I will try on all 3 systems and let you know..

thanks..
 

Nokia

Active Member
Licensed User
Longtime User
Not so sure why, but can you try with this code, I fixed an error:
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 Object = Array As String(e.GetDataObjectForId("text/uri-list"))
    For Each TextLink As String In TextLinks
        Dim Links() As String = Regex.Split("\r\n", TextLink)
   
        If Links.Length > 0 Then
            For Each Link As String In Links           
                'your code here  
                Log(Link)  
            Next

            e.SetDropCompleted(True)
            Return
        End If
    Next 
End Sub

[edit] What are you trying to drag-drop? This code works with a list of files only


jmon,

I tested your updated code one all 3 systems.. Windows worked fine, but Mac OSX and Linux Ubuntu did not work.. same error.. I don't think it has to do with your code.. the error is coming out of the jDragandDrop Library..
 

jmon

Well-Known Member
Licensed User
Longtime User
error is coming out of the jDragandDrop Library
Could you try this example attached? I wrote my own DragAndDrop library to test where the error comes from.

Download the attachment, run it, then drag your files onto "Button 2" (Example a bit dirty at the moment). Your files should be listed in the text area below.

If my library solves the problem, I'll clean it out and finish it.
 

Attachments

  • DragAndDrop2.zip
    4.4 KB · Views: 325

Nokia

Active Member
Licensed User
Longtime User
Could you try this example attached? I wrote my own DragAndDrop library to test where the error comes from.

Download the attachment, run it, then drag your files onto "Button 2" (Example a bit dirty at the moment). Your files should be listed in the text area below.

If my library solves the problem, I'll clean it out and finish it.

I will download and test on all three systems.. windows 7 and 10, linux and mac os x and let you know.. give me a few days..
 

Nokia

Active Member
Licensed User
Longtime User
Could you try this example attached? I wrote my own DragAndDrop library to test where the error comes from.

Download the attachment, run it, then drag your files onto "Button 2" (Example a bit dirty at the moment). Your files should be listed in the text area below.

If my library solves the problem, I'll clean it out and finish it.


well I got ahead of my self.. went ahead and tested and it work successfully on all systems.. Windows 7 and 10, Ubuntu Linux and OS X El Capitan..
 

Nokia

Active Member
Licensed User
Longtime User
Cool, then I'll finish the library when I get some time.

ya.. let me know when it done.. also I tried it on my outlook client trying to drag and drop attachment .. but come up empty array.. do you think there is a way to get the link to storage location?
 

jmon

Well-Known Member
Licensed User
Longtime User

stevel05

Expert
Licensed User
Longtime User
Just tried the Demo by creating a batch and running as admin and it works as expected. Can you upload a small project that shows the problem?

Edit: That was on windows 10
 

JanPRO

Well-Known Member
Licensed User
Longtime User
Hi,
Can you upload a small project that shows the problem?
I have used the example too. And I am also using Windows 10 (Creators Update). As I have test it also with a batch I am very confused now ...

Only important feature for me is, drag&drop files from other native programs.

Jan
 
Last edited:

stevel05

Expert
Licensed User
Longtime User
OK, either you have to write a test app just doing that, or I do, it's the first step in finding where the problem is. And I don't have the time right now. So if you can create a new test app that implements just the feature you want and see if that works. If not, post it here and I'll take a look.

99 times out of 100 when I do that for my own issues I find the problem.
 

JanPRO

Well-Known Member
Licensed User
Longtime User
Hi,
attached you can find a simple test app. Try to drag&drop a text file to the form, you will see without admin rights it works fine.
Now open cmd (or B4J) with admin rights, and run the jar. Drag&drop will not be accepted in this case.

Jan
 

Attachments

  • TestDragDrop.zip
    915 bytes · Views: 299

JanPRO

Well-Known Member
Licensed User
Longtime User
Ok, I tried wheter drag&drop willl work in other programs when I start them with admin rights. The result: It doesn't work too. After some research it seems, that it doesn't work due to security aspects.
One solution is to outsource the admin rights needed tasks in a command line tool, create a batch which will automatically run this tool as admin and then open this batch via Shell object from your main app.

Jan
 
Top