Solved

JTree-Wanted in a Expanded Mode!!!!

Posted on 2001-08-01
7
660 Views
Last Modified: 2012-08-13
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                                
0
Comment
Question by:Rajeshsp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 15

Accepted Solution

by:
ozymandias earned 25 total points
ID: 6340734
Don't create or refresh the whole tree.

You can just call the fire event methods of your TreeModel.

If you have a TreeNode called tn a TreeModel called model and you add a child you can do :

 
  tn.add(newnodegoeshere);
  model.nodesWereInserted(tn, new int[]{indexOfAddedChild});

Similarly if you delete a child you can call model.nodesWereRemoved(tn, new int[]{indexOfDeletedChild}, new Object[]{deletedChildNode3}).




 
0
 
LVL 15

Expert Comment

by:ozymandias
ID: 6340763
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.
0
 
LVL 15

Expert Comment

by:ozymandias
ID: 6340772
BTW, you can also call the reload method of your TreeModel and specify which node you want reloaded :

  model.reload(tn);
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Rajeshsp
ID: 6343426
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
0
 
LVL 16

Expert Comment

by:Valeri
ID: 6343758
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
0
 
LVL 16

Assisted Solution

by:Valeri
Valeri earned 25 total points
ID: 6343769
>
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
<
Take a look at DefaultMutableTreeNode class help. setUserObject method. You must overwrite toString() method.

to refresh instantly invoke nodeChanged method of DafaultTreeModel
0
 
LVL 5

Expert Comment

by:lwinkenb
ID: 8895255
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
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question