简体   繁体   中英

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.

Recursion is your friend here.

In pseudo code:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM