Unable to update nodes in JTree

Hi all,
I have a JTree, which I have passed in a DefaultMutableTreeNode in the constructor. I have added 3 elements inside this "root". So the JTree looks like this :
Root
->Element 1
->Element 2
->Element 3
However, when I want to actually delete these 3 nodes and add in another 2 nodes, it doesn't work for me, a sample :
//JTree which is created, using DefaultMutableTreeNode
DefaultMutableTreeNode node = new DefaultMutableTreeNode("Root");
//add 3 nodes inside first
node.add(new DefaultMutableTreeNode("Element 1"));
node.add(new DefaultMutableTreeNode("Element 2"));
node.add(new DefaultMutableTreeNode("Element 3"));
JTree jtree = new JTree(node);
//get the root (which has 3 elements now)
DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode)jtree.getModel().getRoot();
//delete the 3 elements
rootNode.removeAllChildren();
//then add in another 2 more nodes
rootNode.add(new DefaultMutableTreeNode("New Element 1"));
rootNode.add(new DefaultMutableTreeNode("New Element 2"));
The jtree created does display the first 3 elements, however when after adding in 2 more new elements, the tree doesnt change.
Any tips and comments will be greatly appreciated! Thanks.

Oops, yeah. My mistake was, The tree should have a model, instead of just nodes connecting to nodes... that's why it wasnt able to update... i've should used a model from the start. its the correct way isnt it :) i can continue my project now .. thanks all

Similar Messages

  • Problem inserting new node into JTree with depthFirstEnumeration()

    Hello,
    I'm currently trying to use depthFirstEnumeration() to add and delete nodes for a simple JTree. I've written a method to handle this, but it keeps coming back with an exception saying that 'new child is an ancestor'.
    All I'm trying to do is add and delete nodes from a JTree using add and remove buttons within a swing program. When a user adds the new node the JTree needs to be updated with new labels in sequential order dependent upon a depthFirst traversal of the JTree.
    My current code for the add button is as follows,
    public void actionPerformed(ActionEvent event) 
            DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)tree.getLastSelectedPathComponent();
            Enumeration e = rootNode.depthFirstEnumeration();
            if(event.getSource().equals(addButton))
                if (selectedNode != null)
                    while (e.hasMoreElements()) {
                    // add the new node as a child of a selected node at the end
                    DefaultMutableTreeNode newNode = (DefaultMutableTreeNode)e.nextElement();
                     // treeModel.insertNodeInto(newNode, selectedNode, selectedNode.getChildCount());
                    //System.out.print(newNode.getUserObject() + "" + newNodeSuffix++);
                    String label = "Node"+i;
                    treeModel.insertNodeInto(newNode, selectedNode, selectedNode.getChildCount());
                    i++;
                      //make the node visible by scrolling to it
                    TreeNode[] totalNodes = treeModel.getPathToRoot(newNode);
                    TreePath path = new TreePath(totalNodes);
                    tree.scrollPathToVisible(path);
                    //System.out.println();
            else if(event.getSource().equals(deleteButton))
                //remove the selected node, except the parent node
                removeSelectedNode();           
        } As you can see in the above code, I've tested the incrementing of the new nodes in a System.out.print() statement and they appear to be incrementing correctly. I just can't see how to correctly output the labels for the nodes.
    Any help and advice always appreciated.

    This is about the 5th posting on the same question. Here is the link to the last posting so you can see what has already been suggested so you don't waste your time making the same suggestion.
    http://forum.java.sun.com/thread.jspa?threadID=704980
    The OP doesn't seem to understand that nodes don't just rename themselves and that renderers will only display the text of the current node. If you want the text displayed to changed, then you need to change the text associated with each node, which means iterating through the entire tree to update each node with new text. Then again, maybe I don't understand the question, but the OP keeps posting the same question without any additional information.

  • Has anyone encounter this "unable to set node credentials for /LDAPv3"?

    Install and updated the Macmini server to 10.6.5. It working fine until try to access the Server Preferences and error message "unable to set node credentials for /LDAPv3/127.0.0.1 with the record name **." Looking at the logs and has servermgr_accounts got error 5203 trying to auth to local LDAP node. Has anyone found solution for this problem?
    Thanks
    Luis

    Thank you for responding. This is what we are using in a small company a Cisco Switcher, and don't have a router.
    If you're getting connections off of the network out to the Internet, then yes, there is a router involved. Somewhere.
    MacMini server I have an IP address of 169.254.xxx.xx, before IP address was 192.254.xxx.xx.
    That IP address implies that the box isn't getting an IP address from a DHCP server; that's the self-assigned block. (Officially, these addresses are in the Automatic Private Address Configuration Automatic Private IP Addressing (APIPA) IANA reserved range.)
    Which implies that at least two problems lurk.
    Mac OS X Server must have a static IP address. Not DHCP-assigned dynamic addresses.
    And a DHCP server isn't answering the IP address requests. (Well, not unless the DHCP server is passing out addresses in the self-assigned block, and that wouldn't likely be considered best-practice. More likely an IP address from a DHCP address pool allocated within a subnet somewhere in the 10.0.0.0/8 or 172.16.0.0/12 or (less desirably) 192.168.0.0/16 private blocks.
    The Firewall is not turned on. Its purpose is for guest to access files, without deleting or modifying it.
    When you're debugging problems, simplify. Divide the problem. With network services, test the lowest levels of the stack. Then work your way up the stack; toward higher-level services and mechanisms. Then add more parts and pieces, and DHCP and related.
    IP hosts operating at 169.254.0.0/16 addresses (for longer than it takes to get an IP address from DHCP) usually implies that the network configuration is invalid or the DHCP server is not working.
    I did not expect that Open Directory would be a big problem.
    If DNS services or IP routing is misconfigured, then the whole rest of the stack will be unstable at best. The configuration order (and debugging order) involves functional IP networking and hardware, first and foremost. Then having functional DNS. Then Open Directory and then Kerberos. Then the rest of the stack.

  • OSX: Adobe Creative Cloud unable to update (stall at 50%)

    Hey experts,
    ever since signing up for Creative Cloud I have been unable to update any application as my regular user on OSX. After exchanging 23 emails with the Adobe support in 2013 I finally gave up and created a workaround in the hope that the Adobe developers would finally look into the issue and fix the bug. With the last update of Creative Cloud my workaround stopped working so I took time to do a complete reinstallation of Creative Cloud to see if the bug was finally fixed. It was not.
    The bug:
    -Installation of Creative Cloud and Photoshop, Lightroom etc. through the Creative Cloud app works.
    -Any try to update a CC applicaton (e. g. Photoshop CC 2014 results in the state "waiting" at 50%):
    -Trying to update through the menu of Adobe Photoshop CC 2014 "Aktualisierungen"
    resulted in the following error message:
    Translation: "Update failed. Unable to apply updates. Adobe Application manager is already running. Close all instances of Adobe Application Manager before applying updates. etc."
    What I tried to resolve the problem:
    What did not work:
    -Complete reinstallation of Creative Cloud:
         -Uninstall of all Adobe applications
         -Ran the Adobe CC Cleaner tool
         -Eliminated every single *[Aa]dobe*-folder on my disk including my profile.
         -Reboot
         -Re-installation using a fresh CC download.
    -The common 1st-level-support acts of desperation:
         -Rebooting
         -Checking the file system
         -Fixing permissions
    -The bug even survived 2 OSX system upgrades
    -Even tried to track down the bug myself which I gave up after having discovered the endless chain of Creative Cloud and AAM-Processes executing each other...
    What worked:
    -Installing updates as another OSX user. (Which is cumbersome and to be honest I am unwilling to create a new profile and redoing the settings of all installed (especially non-Adobe) applications because of an Adobe bug...)
    Any help will be greatly appreciated.
    Patrick

    Sheena Kaul schrieb:
    Hi Patrick,
    Can you try to run the Adobe Creative Cloud on root user account?
    Enabling and using the "root" user in OS X - Apple Support
    Regards,
    Sheena
    Hessijames schrieb:
    What worked:
    -Installing updates as another OSX user. (Which is cumbersome and to be honest I am unwilling to create a new profile and redoing the settings of all installed (especially non-Adobe) applications because of an Adobe bug...)
    Any help will be greatly appreciated.
    Patrick

  • HT204266 My iPad (version 1, IOS 5.1) has quit connecting with the store. I am unable to update or buy any app. I did a reboot and a reset with deleting the data. I can not find anything in support for this problem. Any help will be appreciated.

    My iPad (version 1, IOS 5.1) has quit connecting with the store. I am unable to update or buy any app. I did a reboot and a reset with deleting the data. I can not find anything in support for this problem. Any help will be appreciated.

    My iPad (version 1, IOS 5.1) has quit connecting with the store. I am unable to update or buy any app. I did a reboot and a reset with deleting the data. I can not find anything in support for this problem. Any help will be appreciated.

  • I am unable to update  apps on my iPhone 5.

    I am unable to update my apps on my iPhone 5. As I select the update button it asks for my password but the goes back to like it was. I have already rebooted a couple of times & even logged out & signed back into my iCloud, iTunes & App store. Nothing worked. But, I am still able to download new apps.
    Please tell me what can I do now to update my apps. All suggestions will be appreciated.
    Thank you.

    Can you explain a little more?  Is there a problem with your app store account?  If so, http://www.apple.com/emea/support/itunes/contact.html
    If there is another reason, can you describe it?

  • I am unable to update apps on my iPhone 4. I tried rebooting but still I get an error message which says "unable to update"

    I am unable to update apps on my iPhone 4. I tried rebooting but still I get an error message which says "unable to update"

    I really didnt want to restore unless i had absolutely other option.
    as per usual, apple wont help unless i buy an apple care plan. helpful much.

  • Unable to update apps on iPad mini. I have even restored the iPad and now I can't download any of my previously purchased apps.

    Can someone help me. I am using an iPad mini with iOS 7.0.4 with wifi connection. Have had no problems until recently when I was unable to update apps and then noticed that some apps would open but no data would be available in apps like intelicast and Pinterest. I have restored the iPad and now I am unable to download any of my previously purchased apps.

    1. Make sure iPad is using the latest software
    2. Settings>General>Date and Time>Set Automatically>On
    3. Make sure Time Zone is correct
    4. Reset iPad. Hold the Sleep and Home button down until you see the Apple Logo.

  • Help needed with finding node in JTree

    Hi,
    In my application i will be entering some string data in a text box for search criteria.
    When I click on search, I will get data from database which will be shown as a JTree.
    This Jtree will have some nodes in which, node with string entered in the search text box exists.
    I need to focus on this node and I have only a string to find this node.
    How can I do this?How can I find a node in JTree using string value?
    Is there any alternate option by which I can achive my need?
    Please suggest.
    Thanks.

    @OP: please assign your dukes.
    @Andre_Uhres: if you don't get rewarded in the next couple of days, please let me know here to get at least one duke for your effort.
    Bye.

  • Error: 1013231 Unable to update database while in readonly mode for backup

    Hi all,
    Wen im deleting the members for dimendsion , its giving error (hyperion 11.1 aso)
    Error: 1013231 Unable to update database while in readonly mode for backup , how can i solve this problem ,plz can any one help on this
    Thanks

    Has somebody set the database ready for archiving, maybe some maxl has been run and the db has not been returned from read only mode.
    Try running the following Maxl (change app.db to match your app/db)
    alter database app.db end archive;
    Cheers
    John
    http://john-goodwin.blogspot.com/

  • Unable to Update Database.

    Hi All,
    I was trying to load data thru load files and got the following message.
    Unable to update database while in readonly mode for backup
    Unexpected Essbase error 1013231I tried looking at Information Help Menu.
    I could not find the error number.
    Could anyone help.
    Thanks in advance.
    Bal.

    Hi Atul,
    Thanks for the help.
    The Readonly error got resolved.
    But still the following error is displayed when I am loading data thru load rule.
    To Brief you up, I had done a database corrupt check using validate command because of the following error. The information map asks you to do the same since the other parameters are in the affirmative ie sufficient disk space, not using addsin, File is present.
    *Unable to Read Information From [C:\Hyperion\essbase\app\SMC\PL\PL-BS-LD.rul]*
    Unexpected Essbase error 1019003
    I used the VALIDATE <error.txt> command and found that the database is not corrupt.
    I also used the export command to see if everything goes well. That also works well.
    Note: I do not have any data in the Cube. I had cleared all data.
    Can you please help ?
    Regards
    Bal.
    Edited by: user11091956 on Apr 12, 2010 11:26 PM

  • Unable to update numbering schemes in define purchasing options

    Hi,
    We are unable to update the numbering scheme from manual to automatic in define purchasing options (Numbering Tab). Documentation says that you can update it, but it does not give any reason under what circumstances we would not be allowed to update the numbering schemes.
    Thanks,
    Ketul.

    Hi Sandeep,
    I am doing multi organisation implementation and only one ledger they do not require Inventory and Purchasing modules. Because of that i will not create any inventory organisation for that selected ledger.
    This ledger will have seperate responsibility for AP.
    Howver, my problem is when i am trying to complete the financial options, inventory organisation is mandatory for that responsability. Without inventory organisation i am unable to save the financial options.
    Please assist me how to overcome this issue.
    Thanks,

  • I did a software upgrade to IOS6 and my Iphone4S is now unable to update. Do I lose all my contacts and calendar entries when I restore?

    I did a software upgrade to IOS6 and my Iphone4S is now unable to update. Do I lose all my contacts and calendar entries when I restore?

    You should be syncing all your contacts and calendars with your computer, either via iCloud or iTunes, so it is easy to re-sync them back to the phone after you restore.

  • TS3694 I have a Ipod touch 4G, and i am unable to update or restore it.

    I have been unable to update or restore my Ipod touch to the 5.1, and 11.1 for my computer. each attempt to update has lead to the error report 3194. I'm not sure what it means or how to fix it. Please someone point me in the right direction to get this fixed.
         P.S. - Don't put me thru the Apple support run around.
                             THANK YOU

    Error 1004, 1013, 1638, 3014, 3194: These errors may be the result of the connection to gs.apple.com being redirected or blocked. Follow these steps to resolve these errors:
    Install the latest version of iTunes.
    Check security software. Ensure that communication to gs.apple.com is allowed. Follow this article for assistance with security software. iTunes for Windows: Troubleshooting security software issues.
    Check the hosts file. The restore will fail if there is an active entry to redirect gs.apple.com. Follow iTunes: Advanced iTunes Store troubleshooting to edit the hosts file or revert to a default hosts file. See section "Blocked by configuration: (Mac OS X/Windows) > Rebuild network information".
    Try to restore from another known-good computer and network.
    If the errors persist on another computer, the device may need ser

  • HT1338 i am unable to update my aps i get this message...There was an error in the App Store. Please try again later. (18)... i deleted the cashe.db from the  com.apple.appstore folder...

    i am unable to update my apps i get this message...
    There was an error in the App Store. Please try again later. (18)...
    this has been happeing for weeks

    http://www.apple.com/support/mac/app-store/contact.html?form=account

Maybe you are looking for

  • [Solved] Screen lockup since xorg 1.6.3-4 upgrade (catalyst)

    Hey there, since i yesterday upgradet my system (pacman -Syu) and pacman installed a new xorg-server version (from 1.6.3-3 to 1.6.3-4) and xf86-inpud-evdev my screen gets completely locked up after i start GDM. Only thing that helps is to press the r

  • Using a caculated field to get data from another table.

    I have a Products Table that I need to add a  field to. This field gains data from a Supplier table by using the supplier code to find the correct supplier type. All Products have a Supplier Code. So for example in SQL this would be a simple where st

  • Photosmart 7460 clips part of picture

    When I print on a borderless 4x6, what appears on the screen is different than what is printed. The printed picture has about 1/8" or more cropped all around the picture. How can I fix this do I can print exactly what is on the screen? Thanks, Scott

  • Element Object version Number

    Where can I get the object version number of an element. I cant seem to find it in any of the element tables Thanks

  • Account assignment category Asset to Cost Center in po items

    Hey, We have a Question how to handle this Exception: We have purchase order items with the account assignment category "A - Asset" and we have created Asset master data. Later, this assignment category is changed to "K - Cost Center". But the Asset