java - JTree wont update -


this question has answer here:

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

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -