[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to refresh a particular directory in a Jtree

Posted on 2008-11-20
11
Medium Priority
?
629 Views
Last Modified: 2013-11-23
Hi,
Based on this thread, http://www.experts-exchange.com/Programming/Languages/Java/Q_23793040.html
can anyone please say, how to refresh a particular directory alone, whenever needed.

zzynx, i have reposted this question as per your suggestion. Hope I am clear with my question.

Please provide some help.

Warm Regards,
Sreejith
0
Comment
Question by:Sreejith22
  • 6
  • 5
11 Comments
 
LVL 37

Accepted Solution

by:
zzynx earned 2000 total points
ID: 23002394
1) On the MyTreeNode object corresponding with the particular directory (let's say it is called "nodeToRefresh") call removeAllChildren() (That's a mehtod of the DefaultMutableTreeNode class it extends)

  nodeToRefresh.removeAllChildren();

2) Make sure your MyNode object is up-to-date with the new situation (= the children are reconstructed)

3) Then call

   nodeToRefresh.addSubNodes();

4) call

    ((DefaultTreeModel)yourTree.getModel()).reload(nodeToRefresh);

If needed:
[ 5) If you don't see anything changing visually it might be needed to call

    yourTree.revalidate();
    thePanelWhereTheTreeIsPartOf.repaint();
]
0
 

Author Comment

by:Sreejith22
ID: 23011299
Inside myTree class, is it possible for me to get the vector of contents corresponding to a particular directory?
0
 
LVL 37

Expert Comment

by:zzynx
ID: 23011358
myTree class?
I'm not aware of the fact that you have your own myTree class...
0
Technology Partners: 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:Sreejith22
ID: 23011492
I named the class in which I declare and create the tree as myTree.java

My question is, I get the child vector corresponding to a particular directory with  myNode.getChildren()

Though we add it to the child vector as
>>children.add( new MyNode(dirEntry1.filename, dirEntry1.attributes.isDirectory()) ); , i get the output in the form [my_share, jj, my_music, my_pictures, my_video, New Folder (2), search_off.png, booodrive.png, src.rar] , which is OK for me.

But , when I perform the below mentioned, I get the exception given.

            for(Enumeration e = myNode.getChildren().elements(); e.hasMoreElements();)
            {
                  Object o = e.nextElement();
                  nomSelection =((SFTPv3DirectoryEntry)o).filename;






....................


Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: booodrive.MyNode cannot be cast to com.trilead.ssh2.SFTPv3Dir
ectoryEntry
        at booodrive.myTree.createFileVector(myTree.java:958)



I know that what is inside that vector is a MyNode object, but how can I cast this?
0
 
LVL 37

Expert Comment

by:zzynx
ID: 23011620
>> I know that what is inside that vector is a MyNode object, but how can I cast this?
Well, you only can get the information out of a MyNode object that you previously put in.

I don't know how your constructChildren() method and your MyNode object currently looks like,
but if constructChildren() still contains the line I suggested:

       children.add( MyNode(dirEntry1.filename, dirEntry1.attributes.isDirectory()) );

you see that in your MyNode object you store the filename, so you could write:

for(Enumeration e = myNode.getChildren().elements(); e.hasMoreElements();) {
      MyNode node = (MyNode)e.nextElement();
      nomSelection = node.getName();
      ...
}
0
 

Author Comment

by:Sreejith22
ID: 23011804
ok..thanks very much, I am implementing the refresh for a directory..after that I will close this thread.
thx, again.
0
 

Author Comment

by:Sreejith22
ID: 23012237
I am implementing drag and drop. Everything works fine for me. But one problem occured while implementing this. The solution of which requires me to have the following detail.

If at any time, I select a particular item in a directory(say, directory x), how can I get the children vector of that directory(directory x) from MyNode?

I tried different methods, sorry to say that with my limited knowledge, i could not get the desired vector.

If possible, please help.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 23012290
>> how can I get the children vector of that directory(directory x) from MyNode?
getChildren() returns the Vector containing the children (also MyNode object's again)
0
 

Author Closing Comment

by:Sreejith22
ID: 31518622
Thanks alot zzynx, soln. was awesome
0
 

Author Comment

by:Sreejith22
ID: 23032719
Thanks alot zzynx, solution was awesome and line by line accurate.

0
 
LVL 37

Expert Comment

by:zzynx
ID: 23040095
You're welcome.
Thanx 4 axxepting
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month20 days, 3 hours left to enroll

873 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