Solved

JTree-Wanted in a Expanded Mode!!!!

Posted on 2001-08-01
7
628 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 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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 connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
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:

758 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now