Link to home
Start Free TrialLog in
Avatar of Rajeshsp
Rajeshsp

asked on

JTree-Wanted in a Expanded Mode!!!!

Hai
   I am using a JTree , at times nodes can have child nodes also. The problems now is when ever a new node added or removed, which do happen very frequently,either its a child node or node, I am creating/refreshing the tree. This is keeping my tree in collaped mode. I want my tree to be always expanded mode. Please help me for this problem.
Thanks in advance.
Rajesh.Sp Kann                                
ASKER CERTIFIED SOLUTION
Avatar of ozymandias
ozymandias
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you want an example, download this :

  http://ozymandias.webjump.com/dndjtree2.java

To add a tree node drag an icon off the toolbar and drop it on the node that will be the new node's parent, or right-click on a node and select add from the popup menu.

You can also rename and delete nodes.

On each of these changes the onlt refresh that takes place is the refresh of the parent node, rather than the whole tree.
BTW, you can also call the reload method of your TreeModel and specify which node you want reloaded :

  model.reload(tn);
Avatar of Rajeshsp
Rajeshsp

ASKER

Hello
     That's ok ,in my application when i add a leaf node the Parnt Node(which allows a maximum of 5child nodes) Text(Java) should show the Count(0/05) as:
 Java[1/05] as Title(Parent) and when the second node added the Title of Parent changes toJava[02/05]

Then i take the count from Database so i have to refresh
instantly.Any solution

Regards
Rajesh.Sp Kann
Avatar of Valeri
read "DefaultTreeModel" help. Take a look at methods :
insertNodeInto, removeNodeFromParent and nodeChanged....

Don't call the fire event methods of your TreeModel...
Just update the model using insertNodeInto and removeNodeFromParent methods.

Best regards
Valeri
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Split points between Valeri and ozymandias
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
lwinkenb
EE Cleanup Volunteer