How do you make nodes draggable? If you search for draggable nodes you will find lots of code samples. But most of them don’t consider transformations. Transformations can be applied to nodes to scale them down etc. This is an important feature of JavaFX that unfortunately is not considered by many developers.
Don’t waste so much of JavaFX’s potential!
When I developed the window control I wanted to create draggable nodes that can also be dragged if the node or its parent was scaled. To simplify things, I added a class called MouseControlUtil to the JFXtras. It provides the method
MouseControlUtil.makeDraggable(final Node n);
This is all you need to do to make nodes draggable. Pretty cool, huh?
In the video tutorial I show a sample project that demonstrates how to create lots of draggable rectangles inside of a window control that contains scalable content. We’ll discuss what happens with the mouse pointer if you don’t consider transformations.
Sample project: MakeNodesDraggable01.
What features would you like to see in the future?
Do you need rotation support? What about 3D user interfaces? Tell me your ideas!