KJW
KJW

Reputation: 15251

how to recursively delete all nodes in JTree?

in a JTree comprised of DefaultMutableTreeNodes, how would you traverse and delete starting from a given Node and all it's ancestors?

it should delete starting at it's deepest level , backing upwards to the given Node. the given starting node should be the last thing to remove.

Upvotes: 0

Views: 774

Answers (1)

Ray Toal
Ray Toal

Reputation: 88378

Recursion is your friend here.

In pseudo code:

def deleteTree(root)
    for each child c of root
        deleteTree(c)
    end
    delete root
end

Upvotes: 2

Related Questions