Skip to main content

How to move node in JXTreeTable

1 reply [Last post]
bolsover
Offline
Joined: 2005-01-10
Points: 0

Struggling with this...
I need to change the sequence of some nodes in a JXTreeTable but unsure how best to do.

The nodes extend AbstractMutableTreeTableNode and has methods for insert...

 public void insert(ProdScheduleTreeTableNode child, int index) {
        if (!allowsChildren) {
            throw new IllegalStateException("this node cannot accept children");
        }

        if (children.contains(child)) {
            children.remove(child);
            index--;
        }

        children.add(index, child);

        if (child.getParent() != this) {
            child.setParent(this);
        }
    }

and remove...

 public void remove(ProdScheduleTreeTableNode node) {
        children.remove(node);
        node.setParent(null);
    }

Debugging, I can see that the methods work in that the sequence of nodes is changed when I make the following calls from the model:

ProdScheduleTreeTableNode parent  =  myNode.getParent();
                            parent.remove(myNode);
                            parent.insert(myNode, n);

But... how do I get the GUI to update??

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kleopatra
Offline
Joined: 2003-06-11
Points: 0

notify the model - just the same as with a TreeNode/TreeModel :-) Then all should work, except you stumbled across a bug.

Cheers
Jeanette