Search code examples
clojurejtreeseesaw

How can I update a seesaw tree model?


I've been using seesaw.tree/simple-tree-model to create my TreeModels, the docs say that this is read only. Originally I didn't need to edit the tree structure however now I do!

There is a pull request in seesaw for adding update-tree!. Though this is 8 months old.

What is the best way to create and edit JTrees with seesaw / clojure?


Solution

  • Unfortunately, Seesaw's tree support is pretty lame. JTree (and it's just-as-nasty cousin JTable) is extremely complicated so coming up with a clean wrapper that covers a lot of use cases has proven difficult.

    Anyway, if you want an editable tree model, you're going to have to either create your own implementation of TreeModel, or build off of DefaultTreeModel, tutorial here. The key with DefaultTreeModel is to always make modifications (adding/removing children, etc) through the DefaultTreeModel object rather than the nodes directly. This ensure that events are fired correctly and the tree is repainted, etc. If you find yourself manually calling updateUI or anything like that on the tree, you're doing something wrong.

    Hope this helps. Sorry about the inconvenience. It just makes me sick to think of someone using Seesaw having to do interop :)