Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

JTree-Wanted in a Expanded Mode!!!!

Posted on 2001-08-01
7
Medium Priority
?
687 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
7 Comments
 
LVL 15

Accepted Solution

by:
ozymandias earned 75 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
Industry Leaders: 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 75 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

782 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