java - JTree wont update -
this question has answer here:
- how update jtree elements 5 answers
i trying add node jtree. so:
defaultmutabletreenode root = (defaultmutabletreenode) tree.getmodel().getroot(); defaultmutabletreenode newnode = new defaultmutabletreenode(event.getobjectthathaschanged()); root.add(newnode); ((defaulttreemodel) tree.getmodel()).reload();
however, tree doesnt update. ive read posts reload() supposed call, no effect. please note being called on edt. ideas?
edit:
i have tried approach:
defaultmutabletreenode root = (defaultmutabletreenode) tree.getmodel().getroot(); defaultmutabletreenode newnode = new defaultmutabletreenode(event.getobjectthathaschanged()); ((defaulttreemodel) tree.getmodel()). insertnodeinto(newnode, root, root.getchildcount() - 1);
still no go. however, when shut program down , reopen it, new node there. (i persist data).
add nodes jtree using defaulttreemodel
's insertnodeinto method. quote api
this message nodeswereinserted create appropriate event. preferred way add children create appropriate event.
for example:
((defaulttreemodel) tree.getmodel()).insertnodeinto(newnode, root, 0);//inserts @ beginning //((defaulttreemodel) tree.getmodel()).insertnodeinto(newnode, root, root.getchildcount() - 1);//inserts @ end
Comments
Post a Comment