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
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 )
- 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 )
- 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 )
- 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 )
- 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 )
- 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
Last edited: