Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

JTree-Wanted in a Expanded Mode!!!!

Posted on 2001-08-01
7
Medium Priority
?
677 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 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

730 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