API proposal: drag view

Pavel Safrata pavel.safrata at oracle.com
Mon Jan 14 07:13:30 PST 2013

Hi Scott,
the problem with using an ImageView as you did is that we cannot render 
it to an image unless it is part of the scene. Including an ImageView 
that you don't want to have in scene only for using an image in an API 
that takes images sounds crazy.

I think of the image-accepting method as the main method of the API. The 
other method is a convenience method that removes the necessity to do 
the snapshot manually in the most common case.


On 14.1.2013 16:02, Scott Palmer wrote:
> It is trivial to wrap an Image in an ImageView.  Is there really a 
> need for two methods?
> I assume setDragView(new ImageView(img), dx, dy) is equivalent to 
> setDragView(img, dx, dy).
> Other APIs don't special case Image like this. E.g. the constructor 
> for Label (and other controls) is Label(String, Node) and it does not 
> also have Label(String, Image).
> Regards,
> Scott
> On Mon, Jan 14, 2013 at 2:59 AM, Pavel Safrata 
> <pavel.safrata at oracle.com <mailto:pavel.safrata at oracle.com>> wrote:
>     Hello,
>     this is a proposal of an API allowing to specify the image
>     floating with mouse cursor during a drag&drop operation.
>     Jira: http://javafx-jira.kenai.com/browse/RT-14730
>     I propose to add two methods to DragBoard:
>     setDragView(Image image, double offsetX, double offsetY)
>     setDragView(Node node, double offsetX, double offsetY)
>     The first one simply uses the given image for the drag view with
>     the offsetX and offsetY specifying cursor position over the image.
>     The second one renders the given node to an image and uses the
>     result (the coordinates being in the node's local space).
>     The typical usage will look like this:
>             sourceNode.setOnDragDetected(new EventHandler<MouseEvent>() {
>                 public void handle(MouseEvent event) {
>                     Dragboard db =
>     source.startDragAndDrop(TransferMode.ANY);
>                     ClipboardContent content = ...
>                     db.setContent(content);
>                     db.setDragView(sourceNode, event.getX(),
>     event.getY()); // that's it
>                     event.consume();
>                 }
>             });
>     This API is meant for telling the operating system what visual
>     cues to provide, I don't think it is useful (and I'm not sure it
>     is even possible) to provide getters.
>     There is a possibility to provide default drag view - if none of
>     those methods is called, the default drag view would be an image
>     of the drag gesture source. This should work nice most of the
>     times. However, it may cause inconveniences to some existing apps
>     - for instance a text editor node which puts the selected text on
>     the DragBoard - after updating FX the application starts to show
>     the entire editor in the drag view. For this reason I think the
>     default behavior should remain unchanged.
>     Thanks,
>     Pavel

More information about the openjfx-dev mailing list