Posts Tagged ‘drag’

JavaFX – Drag and Drop

July 20, 2009 1 comment

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: , ,