JTree Path expansion help

Hi,
I have made my own jtree to load all the directories in the c drive. I am making a simple windows type browser. I allow users to select a driectory and create a new directory within it. The thing is, once this new directory is created it doesnt show up so i reinitialize the JTree to load all the directories again, and this time the new directory shows up in the directory it was created in. The problem is that before i reinitialize the tree again, i save a treepath for the directory the user is creating a new directory in., but after i reinitialize the tree i need to expand back to that path, i try using expandPath(savedTreePath) but its not working. Any ideas? Code is below.
private class NewFolderListener implements ActionListener {
          public void actionPerformed(ActionEvent evt) {
               DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) tree
                         .getLastSelectedPathComponent();
               if (selectedNode == null) {
                    System.out.println("New folder not created");
                    return;
               File temp = (File) selectedNode.getUserObject();
               String newFolderPath = temp.getAbsolutePath() + "\\" + "New Folder";
               System.out.println(temp);
               temp = new File(newFolderPath);
               temp.mkdir();
                        TreePath tp = new TreePath(selectedNode.getPath);
               makeTree();
                         tree.expandPath(tp);
//Reinitialize tree method
private void makeTree() {
          try {
               //setLook();
               tree = new SimpleTree("C:\\");
               //location.setText("C:\\");
               splitPane.setLeftComponent(new JScrollPane(tree));
               tree.addTreeSelectionListener(new TreeSelectionListener() {
                   public void valueChanged(TreeSelectionEvent e) {
                       DefaultMutableTreeNode node = (DefaultMutableTreeNode)
                                          tree.getLastSelectedPathComponent();
                       if(node!=null){
                            MyFile mf = (MyFile)node.getUserObject();
                            location.setText(mf.getAbsolutePath());     
                            fselected = mf;
                       makeRightPane();
               tree.setExpandsSelectedPaths(true);
               //cp.validate();
          } catch (Exception e) {
     }Anyone have any idea what i am doing wrong?

Well ive tried using the tree model, calling methods
such as reload() reload(node) , but none of the
reloaded the new directory which was created for the
node.The reload() method is only useful when you have modified existing nodes.
Use other methods defined in DefaultTreeModel to change tree structure.

Similar Messages

  • How to get the JTree path including the rest of its node

    I want to listen for expansion and collapse events in a JTree including the rest of all its children and nodes. Because if the tree have some similar or same nodes at the upper level, it is hard to know which node has been selected. That is why I want to know all its children.
    I think the traditional way can not be implemented.
    JTree tree = (JTree)evt.getSource();
    TreePath path = evt.getPath();
    Does someone has any idea?
    Thank you.

    My code below turns the selected node in a tree into a Complete Window's Style Path:
        //Get the Path
        TreePath path = tree.getSelectionPath();
        String address;
        if (path == null) return;
        address = new String();
        //Convert Path to String: format is [ root , subtree1, node2, child 3] etc
        address = path.toString();
        //Lop first bit off leaving root, subtree1, node2, child 3]
        address = address.substring(1);
        //Convert ", " into "\" character to make root\subtree1\node2\child 3]
        //replaceAll method uses regular expressions - hense \\\\ only equals one
        ///after being processed..
        address = address.replaceAll(", ","\\\\");
        //remove trailing ]
        address = address.replace(']','\\');This may be what your looking for, or alternatively, it may not.
    Hope it helps set you in the right direction.
    Phillip Taylor
    www.geocities.com/PhillipRossTaylor/

  • JTree path

    I built a JTree thanks to several DefaultMutableTreeNode, wich were instantiate by:
    new DefaultMutableTreeNode ( MyCategory );
    MyCategory is an object from a class I made by my self (class CategoryNode)
    The snag is, once I have this tree, I retrieve a given CategoryNode, and I must set the selection of my tree so that this CategoryNode is the one that will be selected.
    I do not understand how to do it. I tried with the "setSelectionPath(TreePath path) " method, but I do not know how to built the TreePath. I do not understand how it works.
    Someone can help me ? Someone as an example of this ?
    Thank you very much !
    Sylvain.

    My english as bad as yours:-))
    i'm russian
    Just an example of finding suitable node.
    import javax.swing.*;
    import javax.swing.tree.*;
    class Test extends JFrame
    public Test()
    super("Test");
    DefaultMutableTreeNode root=new DefaultMutableTreeNode("ROOT");
    DefaultMutableTreeNode n1=new DefaultMutableTreeNode("1");
    DefaultMutableTreeNode n2=new DefaultMutableTreeNode("1_1");
    n1.add(n2);
    String category="founded";
    n2=new DefaultMutableTreeNode("1_2");
    n1.add(n2);
    root.add(n1);
    DefaultMutableTreeNode nnnn=new DefaultMutableTreeNode(category);
    n2.add(nnnn);
    n1=new DefaultMutableTreeNode("2");
    root.add(n1);
    JTree tree=new JTree(root);
    DefaultMutableTreeNode node=findNode(root,category);
    tree.setSelectionPath(new TreePath(node.getPath()));
    JScrollPane scroll=new JScrollPane(tree);
    getContentPane().add(scroll);
    setSize(300,300);
    setVisible(true);
    public DefaultMutableTreeNode findNode(DefaultMutableTreeNode localRoot,Object category) {
    DefaultMutableTreeNode resultNode=null;
    if (localRoot.getUserObject().equals(category)) {
    return localRoot;
    int cnt=localRoot.getChildCount();
    for (int i=0; i<cnt; i++) {
    DefaultMutableTreeNode tempNode=findNode((DefaultMutableTreeNode)localRoot.getChildAt(i),category);
    if (tempNode!=null) {
    return tempNode;
    return resultNode;
    public static void main(String a[])
    new Test();
    best regards
    Stas

  • JTree path selection

    I have a JTree on the left scrollpane and on clicking the value of a node, I display the value in a text field on the right scrollpane. I change the value and set the value in the JTree . I am unable to make the edited tree path selected. The methods provided in the API do not seem to work.

    Don't the JTree.makeVisible( ... ) or JTree.scrollPathToVisible( ... ) methods help?
    kind regards,
    Jos
    Edited by: JosAH on Aug 23, 2009 6:19 PM: typo

  • JTree - need some help!

    Hello ,
    I need some help with JTree
    I'm writing an aplicaion that includes JTree , but Default JTree is not enough cause near to each intersection (not leaf) I need to display square with different color , I don't care if the square will replace the icon of tree or will be located close to the text (intersection name)
    I don't know how to do it exactly
    Please help me!!
    Thanks a lot!

    more easy with UIManager, put it at the beginig of your application:
    UIManager.put("Tree.closedIcon",
    new ImageIcon(gifp + "folder.gif"));
    UIManager.put("Tree.openIcon",
    new ImageIcon(gifp + "folder_open.gif"));
    UIManager.put("Tree.leafIcon",
    new ImageIcon(gifp + "puntaflechaamarilla.gif"));
    UIManager.put("Tree.expandedIcon",
    new ImageIcon(gifp + "arbol-menos.gif"));
    UIManager.put("Tree.collapsedIcon",
    new ImageIcon(gifp + "arbol-mas.gif"));
    where gip is the gif's path.

  • JTree path question

    I have created a program that basically simulates single celled organisms in a random (non graphical) world, and I want to use a JTree to show the family history and allow the user to bring up an organism's stats by clicking on in the the Jtree, but I have a problem. Each organism has a unique ID number (starting at 0) and that's what I want to display on the tree. I have the code working to add the new organisms to the root, but I want them added as a child to the parent (each child has only one parent for these organisms), but I don't know how to do it. I tried using insertNodeInto but since everything after the root is dynamically generated I don't know how to identify the parent correctly (just using the ID doesn't seem to do anything). Do I need to create a method that somehow copies the entire treemodel into a collection and steps through it? I have the organisms in a collection already (an arraylist to be exact), so I could figure out the lineage by stepping through that, but then how do I build a 'selection path' object that will work to tell Java exactly where I want the child to go? Is the selection path just some kind of array, or is it even possible to build a selection path without a user clicking on a tree node? I hope you can figure out what I'm trying to say here and I appreciate any help you can give.

    Start by creating a Map that has your organisms as the key and the nodes they are in as the value. Or just let the organism include a reference to the node that contains it. Either of those would allow you to identify the TreeNode that contains a particular organism.

  • How to activate mouse right click  on a JTree PATH

    Hi,
    I'm trying to generate a pop menu in a Jtree on mouse event right click.
    So far it is okay, but the problem I have now is to popup the menu only if a precise element of the Jtree is selected.
    Here is some pieces of my code :
    private void fill_panelCenter() {
    stmt.init(conn.getconn());
    ttree.build_root(racine, stmt.getTables(), stmt.getViews(), stmt.getIndexes(), stmt.getPackages(), stmt.getProcedures(), stmt.getFunctions());
    NewTree = new JTree(ttree.getracine());
    NewTree.setBounds(new Rectangle(0, 0, 288, 677));
    trexTree.setVisible(false);
    NewTree.setVisible(true);
    NewTree.addTreeSelectionListener(new TreeSelectionListener(){
    public void valueChanged(TreeSelectionEvent e)
    popup.add("Edit");
    NewTree.addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
    NewTree_mouseClicked(e);
    jScrollPane1.getViewport().add(NewTree, null);
    panelCenter.add(jScrollPane1, null);
    private void NewTree_mouseClicked(MouseEvent e) {
    if (e.get && e.getButton() == 3) {
    popup.show(e.getComponent(), e.getX(), e.getY());
    }

    Hi,
    Thanks for tip, well i didn't use exactly what was there but it help me
    make my own.
    And i find it a bit more simple so for anybody who that might help :
    NewTree.addMouseListener(new MouseAdapter() {
    public void mousePressed(MouseEvent e) {
    if (e.getButton() == 3) {
    TreePath path = NewTree.getPathForLocation(e.getX(), e.getY());
    if (path != null) {
    popup.show(NewTree, e.getX(), e.getY());
    Remember to replace NewTree by your own !
    :-D
    Well well I just need to make the path selected now .... I mean after the right click so the user knows which path he has selected.
    Any ideas ?

  • BW upgrade - landscape / development paths - need help

    hi - is there any whitepaper or oss note that helps provide some best practice for how to handle a landscape during a bw upgrade.
    normally you would have the "normal" path to production where development occurs and is transported up.  and normally in an upgrade there is some sort of dual-path i believe.  the alternate path would be used for emergency transports.
    if there were no development going on this wouldn't be a problem, but we have lots of development that the business will want to be able to continue during as we move through a planned ~9 month bw upgrade.  at some point it has to be really frozen, but i think for the larger portion of the project there can be a workaround to allow development to continue.
    any help is appreciated.

    Hi
    You are correct.
    There are 2 main options:
    1. Duel landscape, 1 for Dev and 1 for sustaiment.
    2. Parallel work on 2 dev's and QA is refreshed and frozen before major releases.
    3. a third option is multi clients (We explored it but did not think it is viable).
    Reg's
    Edan

  • ORA-12008: error in materialized view refresh path ;;; PLZ HELP ME

    Hi all,
    I 'm using Oracle Database 10g Enterprise Edition Release 10.2.0.1.0; I got these errors when I tried to refresh my materialized view ;
    ORA-12008: error in materialized view refresh path
    ORA-01555: snapshot too old: rollback segment number 5 with name "_SYSSMU5$"
    too small
    ORA-06512: at "SYS.DBMS_SNAPSHOT", line 2255
    ORA-06512: at "SYS.DBMS_SNAPSHOT", line 2461
    ORA-06512: at "SYS.DBMS_SNAPSHOT", line 2430
    I don't understand what mean these errors and why i got them?
    Someone can help me please ?
    Thanks
    regards,

    thank you Justin,
    I found in my alertDB.log this line ;
    Mon Aug 20 03:00:54 2007
    ORA-01555 caused by SQL statement below (SQL ID: 64a7sdbbvknta, Query Duration=1021 sec, SCN: 0x0004.4a145344):
    Mon Aug 20 03:00:54 2007
    INSERT /*+ BYPASS_RECURSIVE_CHECK */ INTO "MANAGEMENT"."MVIEW_COMPUTERS"("ID","WINVERSION","ANTIVIRUS","GUID","INSTALLDT","CONNECTION_TYPE","GROUPID
    ","QUOVACOUNTRY") SELECT "C"."ID","C"."WINVERSION","C"."ANTIVIRUS","C"."GUID","C"."INSTALLDT","C"."CONNECTIONTYPE","C"."GROUPID","C"."QUOVACOUNTRY"
    FROM "MANAGEMENT"."COMPUTERS" "C"
    So i execute this query to found the TUNED_UNDORETENTION value ;
    SELECT *
    FROM V$UNDOSTAT v
    WHERE v.MAXQUERYID = '64a7sdbbvknta'
    and i have this result :
    BEGIN_TIME     20070820 02:53:42
    END_TIME     20070820 03:03:42
    UNDOTSN     1
    UNDOBLKS     51242
    TXNCOUNT     5012
    MAXQUERYLEN     1060
    MAXQUERYID     64a7sdbbvknta
    MAXCONCURRENCY     21
    UNXPSTEALCNT     0
    UNXPBLKRELCNT     0
    UNXPBLKREUCNT     0
    EXPSTEALCNT     14
    EXPBLKRELCNT     51392
    EXPBLKREUCNT     0
    SSOLDERRCNT     1
    NOSPACEERRCNT     0
    ACTIVEBLKS     606920
    UNEXPIREDBLKS     19896
    EXPIREDBLKS     612728
    TUNED_UNDORETENTION     1841
    I don't know exactly which value i should set my parameter?
    Message was edited by:
    HAGGAR

  • Invalid handle to path? Help!

    I dowloaded a program LOGOS and it keeps on crashing. Their tech people said it came down to this problem. Can anyone help me with this 'path'? She said it may be something with LION and not being downloaded properly?
    Error detail: IOException: Invalid handle to path "/var/folders/15/bq7_xhf94zv6z1byk1rvjmf00000gn/T/tmp7bcd7658.tmp"

    Run through this list of fixes, I suspect by #8 all will be well.
    Step by Step to fix your Mac

  • Invalid handle to path? Help please!

    I dowloaded a program LOGOS and it keeps on crashing. Their tech people said it came down to this problem. Can anyone help me with this 'path'? She said it may be something with LION and not being downloaded properly?
    Error detail: IOException: Invalid handle to path "/var/folders/15/bq7_xhf94zv6z1byk1rvjmf00000gn/T/tmp7bcd7658.tmp"

    Is this still an issue (it's been a while since this was posted)?  If so, I'd encourage you to post on the Logos community forums or to call Logos customer support.
    I happen to know that a very similar issue was recently fixed for a customer by restarting the indexer.

  • Path To Help on CRM 7.0

    Dear Friends:
    What is the path to get help on crm 7.0 on help.sap.com
    Regards | Pradeep

    I have found the solution myself... help.sap.com > SAP Business Suite > Customer Relationship Management > SAP CRM 7.0 > Open > Application Help > English
    Self Help also Works

  • Java path finding help

    Hello,
    I'm at present working on a route finding system for the london underground as a MIDP application in Java.
    I have a vector of vectors data structure to store the stations as nodes and lines as edges respectively but need a shorest path algorithm to search from one station to the next taking into account line changes.
    Dijkstra's algorithm seems to be the best solution but hard for me to implement.
    Any help on this would be most appreciated.
    Thaxs.
    ash

    I found Dijkstra's algorithm extremely easy to implement by a recursive routine. I found it easiest to work backwards (it simplifies setting the route direction).
    Each node holds a field from distance from the destination, set them all to infinity initially. The node also has a field for next node on the route.
    Then you have a method of the node which offers a route to a node. The arguments are the next node in the route and the resulting distance. The method does nothing if the route offered is longer than one it already has. Otherwise it sets the new length and route to the one on offer and offers itself to all neigbouring nodes.
    Then you just call it on the destination node with a distance of zero and a null route.
    Something like this;
    class Link {
          Station start;
           float length;
    class Station {
         Float distance;
         Link nextStep;
          ArrayList  incomingLinks;
        public void djikstra(float newDistance, Link route) {
              if(distance == null || distance.floatValue() > newDistance) {
                    distance = new Float(newDistance);
                    nextStep = route;
                    for(Iterator it = incomingLinks.iterator(); it.hasNext();) {
                        Link incoming = (Link)it.next();
                        incoming.start.djikstra(newDistance + incoming.length, incoming);
          }(This assumes that if a link is two-way two Links must be created).

  • Update the path, Please HELP !!

    Hi, I know this has been widely described in a Help section, but It does not work for me.
    Os = Windows 2000
    I set the path in control panel, system, advanced, Environment Variables, I click New in User Variables, I put javac in Variable and C:\Program Files\Jdk1.2.2\bin in Variable value.
    Then in the command promt, I type javac helloworld.java and I got the message "Javac is not recognized as an internal or external command, operable program or batch file.
    Where did I get it wrong ? I have only one Java, jdk1.2.2, I'm also using the Opera browser that had previously installed jdk1.3, but I uninstalled it.
    Thank you for your help,
    Antoine

    Simon,
    Classpath is used for finding the Library files (.class files) while path is used for finding the executables(.exe .bat .com etc..)
    Now the problem the poster had was that he was not able to execute the "java.exe". For this to happen, he needs "java.exe" which is under <jdk_home>/bin directory to be in the Path.
    Thats why jsalnoen and me have given him that suggestion. You may suggest why classpath needs to be setup for executing java.exe
    By the way, I dont think you need to reboot the machine after setting the Path. Just close and reopen your dos command prompt window.
    Hope this helps.
    Best Regards,
    Manish

  • There are some space between paths, please help me to solve this

    Hello everyone, i've little question about paths. I get this problem everytime, i searched and didn't find answer.
    There are some space between two different colored paths. There is image below to show the problem more open.
    Thanks for helping.

    sscayir,
    It looks like the screen artifact/Anti-Aliasing issue so often discussed here.
    You may get rid of it by unticking Anti-Aliased Artwork in Edit>Preferences>General, and see more pixelation on screen, but you will probably find that the artifact remains at the same size when you zoom in and that it will not show in PDFs, print, and raster images created by exporting or Save for Web; and yet again, it may be a real issue.
    Which is it?

Maybe you are looking for

  • How to uninstall applications in SCCM 2012 R2

    Hi, We have installed following applications using "Applications" mode of SCCM 2012 R2. XML Notepad Notepad++ Adobe Reader XI How do we uninstall these applications from clients using SCCM 2012 R2? Do we create deployment type for each and uninstall?

  • ASSEMBLY LANGUAGE FILE TO .CLASS --- URGENT!!!!

    Can someone please tell me how to convert a MIPS assembly language file to a .class so I can run it in a JVM? It's URGENT (there's a bus about to hit me and the driver will only stop if I can tell him how to do this).

  • Audigy 2 ZS Platinum Pro/Sound card quest

    Hi all, Since the I/O box on the Platinum Pro series has no rca out connection, does anybody know if I can use the lines out on the card at the same time the I/O is plugged into it's Thanks, Dale

  • Sockets Problem - 2

    Per Dr.Clap's request I have created a new thread....here is the code import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintW

  • Hour clocks?

    II'm looking to have a pie chart where I can show a one hour clock i am helping out at a radio station and need to have an accurate template of when presenters play songs, talk, play ads and so forth. Is this possible in Numbers? sorry if it's a dumb