Home > javafx > JavaFX – Drag and Drop

JavaFX – Drag and Drop

JavaFX does not support Drag-n-Drop by default. But we can wrap javafx Node in a SwingComponent so as to support this feature.

In below applet the list of products is obtained using Yahoo Product Search API. Each of the thumbview is wrapped around a swing component which supports drag and drop. User can drag the product and drop it on to shopping-cart. Once the shopping is complete, user can click on “green arrow” so as to check-out. A list of item bought by user is shown. Click on list to go back to shopping mode.

For Applet mode, click on above image

For standalone mode

Above sample uses DataFlavor.javaJVMLocalObjectMimeType. But it can be easily enhanced to support other DataFlavors like javaFileListFlavor. DragSource is wrapped in SwingDragSource and DropTarget is wrapped in SwingDropTarget. ThumbView is DragSource and ShoppingCart is DropTarget.

Try it out and let me know feedback

Categories: javafx Tags: , ,
  1. July 21, 2009 at 11:28 AM

    This is a great post, thanks for sharing! If you’d be interested, I’d love to hold an interview with you on my web 2.0 blog. Check it out, if you’d like : http://www.insidethewebb.com/

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: