TreeWrapper (version 2)

I was tired of reinventing the wheel whenever I had to implement drag and drop in Swing.

So I decided to build a small Java library that adds drag and drop support to any JTree. Features include:

  • No need to extend JTrees: any JTree (or derivative) will work.
  • Provides visual feedback for drag and drop, but respects existing custom cell renderers.
  • Automatically expands collapsed nodes during drag and drop
  • Automatically scrolls the JTree during drag and drop
  • Supports drag and drop operations between different JTrees
  • Supports both copy and move operations
  • Automatically bans dragging a parent into a child
  • Allows for string-to-tree drag and drop (so you can drag from a JTextComponent, for instance)
  • Easily customizable: using special listeners you can veto a drag and drop operation
  • Adds support for custom popup menus in trees

Version 2 includes the following features: