B4J Library B4JDragToMe - drag and drop

Unless I am mistaken, there is neither a library nor built-in functionality available for B4J which lets you drag and drop a file from Explorer to a Target-object in your B4J app.

I needed this functionality for a project I am working on and came up with a small library.
Please note that I only needed the functionality to drag and drop an object onto a Target-object so I could get the filepath or Url of the object dropped. Thus, no actions are taken when the object is dropped - only an event will be fired with filepath/Url.

This library has 4 (actually 5 - see below) different objects to be used according to the control/view you want to use. They are:

1) B4JDragToMe (for most controls, including some panes)

2) B4JDragToMeCanvasView (for canvas)

3) B4JDragToMeImageView (for ImageView

4) B4JDragToMePaneView (for AnchorPane, GridPane etc)

However, the java-code could be a base for extending the library to add full support for drag and drop in B4J. To show this, I have included in the library the B4JDragToMeCompleteImageView-object which will load an imageview with the image you drop onto it. See the corresponding java-code to see how this is implemented.

The Java-code is attached and free to use for anyone who would like to improve it. I also attach the compiled library if anyone wants to use it.

Usage:
Initialize the library and set a control/view.
In the ReceivedFilePath event, you can get the file-path/Url of the file you dragged and dropped onto the control/view.
I have attached a demo-app.

Please remember that creating libraries and maintaining them takes time and so does supporting them. Please consider a donation if you use my free libraries as this will surely help keeping me motivated. Thank you!



B4JDragToMe
Author:
Moster67 aka Mikael Osterhed
Version: 0.8
  • B4JDragToMe
    Events:
    • ReceivedFilePath (Filepath as String As )
    Methods:
    • Initialize (Control As Control, EventName As String)
      Initialize by setting your ControlView and giving an event-name.
      For files, the event ReceivedFilePath returns the filepath/location of the dragged object
      while it will return the URL for an http-link.
  • B4JDragToMeCanvasView
    Events:
    • ReceivedFilePath (Filepath as String As )
    Methods:
    • Initialize (CanvasView As Canvas, EventName As String)
      Initialize by setting your CanvasView and giving an event-name
      For files, the event ReceivedFilePath returns the filepath/location of the dragged object
      while it will return the URL for an http-link.
  • B4JDragToMeCompleteImageView
    Events:
    • Result (Success as Boolean As )
    Methods:
    • Initialize (ImageView As ImageView, EventName As String)
      This object will load an image onto an imageview.
      Initialize by setting your ImageView and giving an event-name.
      The result-event will indicate if the operation was successful or not.
  • B4JDragToMeImageView
    Events:
    • ReceivedFilePath (Filepath as String As )
    Methods:
    • Initialize (ImageView As ImageView, EventName As String)
      Initialize by setting your ImageView and giving an event-name
      For files, the event ReceivedFilePath returns the filepath/location of the dragged object
      while it will return the URL for an http-link.
  • B4JDragToMePaneView
    Events:
    • ReceivedFilePath (Filepath as String As )
    Methods:
    • Initialize (PaneView As Pane, EventName As String)
      Initialize by setting your PaneView and giving an event-name
      For files, the event ReceivedFilePath returns the filepath/location of the dragged object
      while it will return the URL for an http-link.
 

Attachments

  • B4JDragToMe_JavaCode.zip
    6.5 KB · Views: 514
  • B4JDragToMe_libs.zip
    14.8 KB · Views: 574
  • DragToMeSample.zip
    475 KB · Views: 560
Last edited:

moster67

Expert
Licensed User
Longtime User
Updated the library so it supports most controls/views. Limitation: The purpose of this library when I wrote it was so I could get the filepath or Url of the object dropped. Thus, no actions are taken when the object is dropped - only an event will be fired with filepath/Url.
However, in this latest version of the library, I have included an object that will load an imageview with the image you drop onto it.
Java-code is included so if anyone who wants to expand the library can do it.
 

lymey

Active Member
Licensed User
Longtime User
Updated the library so it supports most controls/views. Limitation: The purpose of this library when I wrote it was so I could get the filepath or Url of the object dropped. Thus, no actions are taken when the object is dropped - only an event will be fired with filepath/Url.
However, in this latest version of the library, I have included an object that will load an imageview with the image you drop onto it.
Java-code is included so if anyone who wants to expand the library can do it.
I like the idea, but I downloaded the sample app, and the library. The program runs, but the form shows doesn't appear to do anything. Is there a prerequisite I am missing?
 

moster67

Expert
Licensed User
Longtime User
As I wrote, when you drop something you will get an event with the file path.
I am on the train now so I cannot check but the sample should work fine with an imageview or else I might not have understood your question property.
 

lymey

Active Member
Licensed User
Longtime User
As I wrote, when you drop something you will get an event with the file path.
I am on the train now so I cannot check but the sample should work fine with an imageview or else I might not have understood your question property.
There doesn't seem to be an event, and no indication that the imageview has been 'selected'. No log entry.
 

moster67

Expert
Licensed User
Longtime User
When the forms opens, you can see various objects. Now drag a file, image (whatever) object from your desktop or explorer over some of the objects in the form (I might not have activated them all) and you will see the cursor change into a link-image. Drop it on the object and you can see a log in B4J showing the origin of the dragged object. If you drag an image onto the imageview, you will see the imageview be loaded with the new image.

It does not work within B4J - there are already other libs for that. What I was missing was something to let me drag something from the desktop or explorer onto a B4J object and I could not find it.

As mentioned in the first post, this is a partial implementation (only the imageview is complete) since I only needed the filepath. I left the jave-code in case someone else would like to implement support for other Javafx-objects.
 

lymey

Active Member
Licensed User
Longtime User
When the forms opens, you can see various objects. Now drag a file, image (whatever) object from your desktop or explorer over some of the objects in the form (I might not have activated them all) and you will see the cursor change into a link-image. Drop it on the object and you can see a log in B4J showing the origin of the dragged object. If you drag an image onto the imageview, you will see the imageview be loaded with the new image.

It does not work within B4J - there are already other libs for that. What I was missing was something to let me drag something from the desktop or explorer onto a B4J object and I could not find it.

As mentioned in the first post, this is a partial implementation (only the imageview is complete) since I only needed the filepath. I left the jave-code in case someone else would like to implement support for other Javafx-objects.
Ok, now I understand - sorry for being dense!
 
Top