Insert node into JTree with own TreeModel

Hi,
I use JTree in combination with my own TreeModel. When a node is removed I use this to inform all listeners:
actListener.treeStructureChanged(new TreeModelEvent(this, pathToRoot));The above works fine. Now if I insert a node and its' parent is already expanded nothing happens at all! I tried to call actListener.treeStructureChanged(new TreeModelEvent(this, pathToRoot)); and actListener.insertTreeNodes(new TreeModelEvent(this, pathToRoot)); without success!
As long as the parent is collapsed and a new node is inserted my getChildCount() method in my TreeModel gets called and the freshly added node will be display correctly but whan the node is already expanded nothing happens.
I've also checked the listeners of my model: one of them is JTree, so it is informed about the insertions but why won't it update its' view? It's especially funny since everything is fine when deleting a node.
Many thanks for any hints.
Regards,
Ren�

I am struggling with the same problem, and have yet to find a solution, maybe some more suggestions can be made? Here is the situation... I've got a JTree and a custom TreeModel. Now, if I do not expand a node, I can insert and delete from it at will using treeStructureChanged(new TreeModelEvent(this,path))and when I expand the node it will have the correct children. However, once I have expanded the node, all attempts to add or remove children are futile. Even if I un-expand the node, changes will not register in the JTree. I've tried out both suggestions already provided in this thread, but to no avail. Additionally, if I reset the root node, all my changes will appear correctly, however the trees "expanded" state is lost and this is not desireable.
Anybody have any advice?

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.

  • Insert Nodes into Hierarchy via ABAP Program

    Hello,
    I want to create ABAP program to insert nodes into a hierarchy.
    I got a class CL_RSSH_HIERMAINTAIN_FRONT with method INSERT_NODES_HIERARCHY .
    But the method is private and cannot be used in the ABAP call.
    I also don't want a pop up which asks for the action on duplicate nodes.
    Can anyone guide me a bit here ?
    Any help would be appreciated.
    Varun

    pl check following
    http://www.scribd.com/doc/7300428/Structure-of-a-Flat-Hierarchy-File-for-Loading-Using-a-PSA

  • Insert Node into XML using XPATH

    Hi,
    I'm having problems inserting a node into a XML. After getting some attributes from the CRC result i'd like to store them in a temp xml variable.
    After that the parent node of the attributes should be inserterd in a goal XML with a repeating node structure.
    Whats the right way to set a node to a certain position in the goal XML?
    Now the only thing i'm getting is erros about transaction:
    Caused by: javax.resource.ResourceException: Transaction is not active: tx=TransactionImple < ac, BasicAction: a307d1e:fd15:4d35c503:1351f50 status: ActionStatus.ABORT_ONLY >
        at org.jboss.resource.connectionmanager.TxConnectionManager.getManagedConnection(TxConnectio nManager.java:304)
        at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnec tionManager2.java:396)
    Etc..
    Thx!

    You can always append new nodes which has a unique tag name (this won't get overwritten).
    Which means, each time when you add a node, it should have tag name which has not already present within the same parent node.
    Later you can replace the tag name with the actual name by using XSL transformations.
    I've tried this in one of my project and worked fine.
    Nith

  • How to get correct node in JTree with DISCONTIGUOUS_TREE_SELECTION mode?

    The following code creats a JTree with DISCONTIGUOUS_TREE_SELECTION mode. When select a single node, the node's name is printed correctly as expected. However, in Window environment, after select one node, if holding the ctrl key and select a different node, the program still prints out the name of the first selected node although both nodes are highlighted. Can some one tell me how to get the name of the second (i.e. the last) selected node printed?
    Thank you very much!
    import javax.swing.*;
    import javax.swing.tree.*;
    import javax.swing.event.*;
    import java.io.*;
    public class TestTree extends JFrame {
    JTree tree;
    public TestTree() {
    super();
    setBounds(0,0,500,500);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    tree = new JTree();
    getContentPane().add(tree);
    TreeSelectionModel model = new DefaultTreeSelectionModel();
    model.setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    tree.setSelectionModel(model);
    tree.addTreeSelectionListener(new TreeSelectionListener() {
    public void valueChanged(TreeSelectionEvent e) {
    Object obj = tree.getLastSelectedPathComponent();
    System.out.println(obj.toString());
    public static void main(String [] args) {
    TestTree test = new TestTree();
    test.show();

    Hi!
    Try this, maybe it's what you want?
    /Smedman
    public void valueChanged(TreeSelectionEvent e)
        TreePath[] paths = tree.getSelectionPaths();
        for (int i = 0; i < paths.length; i++)
            System.out.println(paths.getLastPathComponent());

  • Understanding logminer results -- inserting row into table with CLOB field

    In using log miner I have noticed that inserts into rows that contain a CLOB (I assume this applies to other LOB type fields as well, have only tested with CLOB so far) field are actually recorded as two DML entries.
    --the first entry is the insert operation that inserts all values with an EMPTY_CLOB() for the CLOB field
    --the second entry is the update that sets the actual CLOB value (+this is true even if the value of the CLOB field is not being set explicitly+)
    This separation makes sense as there may be separate locations that the values are being stored etc.
    However, what I am tripping over is the fact the first entry, the Insert, has a RowId value of 'AAAAAAAAAAAAAAAAAA' which is invalid if I attempt to use it in a flashback query such as:
    SELECT * FROM PERSON AS OF SCN #####'  where RowId = 'AAAAAAAAAAAAAAAAAA'The second operation, the Update of the CLOB field, has the valid RowId.
    Now, again, this makes sense if the insert of the new row is not really considered "+done+" until the two steps are done. However, is there some way to group these operations together when analyzing the log contents to know that these two operations are a "+matched set+"?
    Not a total deal breaker, but would be nice to know what is happening under the hood here so I don't act on any false assumptions.
    Thanks for any input.
    To replicate:
    Create a table with CLOB field:
    CREATE TABLE DEVUSER.TESTTABLE
            ID NUMBER
           , FULLNAME VARCHAR2(50)
          , AGE NUMBER  
          , DESCRIPTION CLOB
           );Capture the before SCN:
    SELECT DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER FROM DUAL;Insert a new row in the test table:
    INSERT INTO TESTTABLE(ID,FULLNAME,AGE) VALUES(1,'Robert BUILDER',35);
         COMMIT;Capture the after SCN:
    SELECT DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER FROM DUAL;Start logminer session with the bracketing scn values and options etc:
    EXECUTE DBMS_LOGMNR.START_LOGMNR(STARTSCN=>2619174, ENDSCN=>2619191, -
               OPTIONS => DBMS_LOGMNR.DICT_FROM_ONLINE_CATALOG + DBMS_LOGMNR.CONTINUOUS_MINE + -
               DBMS_LOGMNR.COMMITTED_DATA_ONLY + DBMS_LOGMNR.NO_ROWID_IN_STMT + DBMS_LOGMNR.NO_SQL_DELIMITER)Query the logs for the changes in that range:
    SELECT
           commit_scn, xid,operation,table_name,row_id
           ,sql_redo,sql_undo, rs_id,ssn
           FROM V$LOGMNR_CONTENTS
        ORDER BY xid asc,sequence# ascResults:
    2619178     0C00070028000000     START                  AAAAAAAAAAAAAAAAAA     set transaction read write
    2619178     0C00070028000000     INSERT     TESTTABLE     AAAAAAAAAAAAAAAAAA     insert into "DEVUSER"."TESTTABLE" ...
    2619178     0C00070028000000     UPDATE     TESTTABLE     AAAFEXAABAAALEJAAB     update "DEVUSER"."TESTTABLE" set "DESCRIPTION" = NULL ...
    2619178     0C00070028000000     COMMIT                  AAAAAAAAAAAAAAAAAA     commitEdited by: 958701 on Sep 12, 2012 9:05 AM
    Edited by: 958701 on Sep 12, 2012 9:07 AM

    Scott,
    Thanks for the reply.
    I am inserting into the table over a database link.
    I am using the new version of HTML Db (2.0)
    HTML Db is connected to an Oracle 10 database I think, however the table I am trying to insert data into (via the database link) is in an Oracle 8 database - this is why we created a link to it as we couldn't have the HTML Db interacting with the Oracle 8 database directly due to compatibility problems (or so I've been told)
    Simon

  • Large insert op into table with indexes

    Hi,
    Oracle 8.1.7.0. Empty table (after truncate) with two indexes. Need to insert about 40 billions records. What is better way to complete this task:
    1. Drop indexes, insert data then build indexes.
    2. Simply insert data into table.
    Thanks.

    The only way to find out is to test... For example, I did a test on my single-cpu box with Oracle 9i. My test was to load all the rows from DBA_SOURCE (only 650k rows). I found that a single insert statement with bitmap indexes online ran faster than the total elapsed time for taking the indexes offline, inserting, and bringing the indexes back up...
    With 40-billion rows, I presume you're using partitioned tables and enabling parrallel DML. Thus, your test will be much different than mine...
    In past ETL projects I worked on, I found little difference in timing. I decided that I didn't want to drop indexes (it was ver8i) so I loaded the empty tables with indexes (and constraints) enabled...
    Stan

  • Inserting records into Table with check table logic in place

    I want to insert records into a table, and have the check table to not allow invalid entries.  Is there a function out there that will allow this?  I am currently using the insert statement and it is working except that it is not giving an error when the value does not exist in the check table for the particular fields.
    INSERT INTO ZSD_XREF VALUES WA_XREF.
    That is the basic statement I'm using ZSD_XREF has several fields one being the material number field tied to the check table which happens to be MAKT file.  The insert statement is not validating the material numbers using the check table, or at least it is not giving an error.  Any ideas?

    Paul,
    Unfortunately, open SQL statements such as INSERT, UPDATE do not go through the check table logic as they directly hit the database layer. Check table checks are performed only if you go through application layer that is when you enter the same data through a screen.
    You have to do the checks yourself.
    Happy checking!!!
    Srinivas

  • Insert node in JTree

    Hi!
    I have a JTree created and I need to insert a node in the JTree at a particular path that the use wants. I read the path and the node to be added as a string from the user:
    //Read path and node name
    String path = JOptionPane.showInputDialog (this, "Enter new node path");
    File f = new File (path);
    //Create new child
    DefaultMutableTreeNode child = new DefaultMutableTreeNode (f.getName());
    DefaultMutableTreeNode parent = new DefaultMutableTreeNode (f.getParent());
    //Get model and add new node
    DefaultTreeModel model = (DefaultTreeModel)jTree1.getModel();
    model.insertNodeInto (child, parent, parent.getChildCount());
    child.setParent(parent);
    jTree1.scrollPathToVisible(new TreePath(child.getPath()));
    model.reload();
    But, the new node is not showing up.
    Kindly help,
    x86

    Not pretty, but should give you the idea.import java.awt.event.*;
    import java.awt.*;
    import javax.swing.tree.*;
    import javax.swing.*;
    import java.io.File;
    import java.util.Stack;
    public class Test extends JFrame implements ActionListener {
      DefaultMutableTreeNode root = new DefaultMutableTreeNode();
      JTree jt = new JTree(root);
      File f = new File("C:\\temp\\foo\\bar\\foo.txt");
      public Test() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Container content = getContentPane();
        jt.setRootVisible(false);
        content.add(new JScrollPane(jt), BorderLayout.CENTER);
        JButton jb = new JButton("Add");
        content.add(jb,BorderLayout.SOUTH);
        jb.addActionListener(this);
        setSize(300,300);
        show();
      public static void main(String args[]) { new Test(); }
      public void actionPerformed(ActionEvent ae) {
        Stack s = new Stack();
        File p = (File)s.push(f);
        while (p.getParent()!=null) p=(File)s.push(p.getParentFile());
        DefaultMutableTreeNode current = root, tmp;
        while (!s.isEmpty()) {
          p=(File)s.pop();
          boolean found=false;
          for (int i=0; i<current.getChildCount(); i++) {
            if (current.getChildAt(i).equals(p)) {
             found=true;
             current=(DefaultMutableTreeNode)current.getChildAt(i);
          if (!found) {
            tmp = new DefaultMutableTreeNode(p);
            current.add(tmp);
            current = tmp;
        jt.updateUI();
    }

  • Urgently need help inserting nodes into TreeTable

    Hi, I've got the following problem -
    I use the model that retrieves data from Oracle Database, and it works ok, but when I try to insert new node dynamically, I get very strange reaction of TreeTable and I've been looking where the problem for several hours and I can't find it.
    When I insert the new node I see that the new node is inserted BUT the information in the table doesn't match to the one I've inserted - the node's name is empty and the information in the table just the same as the previous element has.
    I use TreeTable built on the exmple from Sun.
    To notify the TreeTable about changes I use
      public void nodesChanged(){
            TreePath path = treeTableProcess.getTree().getPathForRow(1);
            Object newChild[]= processMonitorModel.newNode();
            int[] ind = new int[newChild.length];
            for (int i=0;i<newChild.length;i++) {
                ind[i] = i;
            processMonitorModel.fireTreeNodesInserted(this,
                                                      path.getPath(),
                                                      ind,
                                                      newChild);
        }I know that TreePath is ok, I checked it out, my node object contains information, the method fireTableDataChanged() get called but the node that I see doesn't contain the information of the node I inserted.
    Thank you in advance!
    Yuri, Germany

    This is the error I get
    Error starting at line 1 in command:
    INSERT INTO PROJECT_CONSULTANT
    (PROJECT_ID, CONSULTANT_ID, ROLL_ON_DATE, ROLL_OFF_DATE, TOTAL_HOURS)
    VALUES
    (1, 100, '06/15/2009', '12/15/2009', 175.00)
    Error report:
    SQL Error: ORA-01843: not a valid month
    01843. 00000 - "not a valid month"
    *Cause:   
    *Action:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Insert data into mySQL with BPEL

    I want to do an insert/update on a table in mySQL. In step 4 of the adapter configuration wizard I select "Perform operation on table" and choose insert/update when I click on next I can see all the tables in the mySQL database but if I choose the table I want to insert to I get the following error message:
    "The following error occurred:
    XX.XX.ZA.tablename
    Please consult the Database Adapter documentation for detailed instructions on how to fix this problem."
    We use BPEL 10.1.2.0.2 and Jdeveloper 10.1.2.3.0
    Thanks
    Roald

    Hi,
    In the same step 4, please try the option pure SQL and enter the query, "select count(*) from tablename"
    Please check whether this is working fine ? And also, were you able to see the records in the JDeveloper IDE with the connecting to the MySQL Database...
    And aslo, the data source you have created for accessing the mySQL Database in weblogic console, what username credentials have you given ? please check whether that username has privileges to the table you want to select ? And , the table you are selecting is under the same username schema or another schema ? If it is a different schema , then find out whether the username you have given while creating the data source has read/write privileges to that table ?
    Thanks,
    N

  • Insert FLV into fla with flv on a streaming server

    I am stuck i need to insert an fla which is on a steaming
    server, i just have the link to the fla on the server, but not very
    good at programming, i know how to put a component for flv in, but
    then do i need to add code or??? can anyone please help

    use the flvplayback component. in the properties panel you
    can choose the skin (with the controls you want) and the path to
    your flv.

  • Bulk insert files into sharepoint with metadata

    Hello everyone,
    I am creating an application which will migrate  about 16k documents and their metadata from a legacy system to SharePoint.
    I got the extract of the legacy system in a way that I have a folder containing the document (pdf file) and an xml file with the metadata per document.
    I created the whole thing to be able to do the upload and it works fine, but on the other hand it is damned too slow...
    I splited the operations, first I upload all the files and then I update the metadata of the files. I also splited the files in batches of 1000 items.
    The file uploading takes more time as the list is filled. At the beginning I needed 15 mins for 1000 files, now that the list has already 3000 files in there, it takes about an hour...
    I do check if the file already exists before uploading it because I need to report an error if the file was already in the list (duplicates detection)
    Is there anyway to improve the performance of the system?
    I also have another issue which is the fact my tool to migrate the files is taking more RAM as the list grows. After the 5000th file my tool is using over 1GB of RAM. Could it be because I use a single SPSite instance for the whole upload? Should I recreate
    it during the upload?
    Here is the code I use in order to upload the files:
    using (var web = _currentSite.OpenWeb())
    var library = web.GetList(libraryName);
    var relativeFileUrl = string.Format("{0}/{1}", library.RootFolder, fileName);
    if (web.GetFile(relativeFileUrl).Exists)
    throw new InvalidOperationException(string.Format("The file '{0}' already exists", fileName));
    var file = web.Files.Add(relativeFileUrl, fileStream, false);
    Thanks a lot for your help!
    With kind regards
    Carlos

    Hi,
    So after a lot of digging the logs and so on, my application was not responsible of the lag on the upload.
    Basically the list I was uploading to was using an event receiver which had a memory leak and was not using the most performant methods in order to retrieve data etc...
    The lags came from the event receiver. Shame is I was the one who developped the event receiver hahaha :)
    Anyway, once the event receiver was fixed, I got much better results for the upload and an upload speed of about 600 files per 10 mins which is totally acceptable for me!
    I also learned in the way the two following facts that might interest people in this situation:
    Event receiver code is loaded in the context of the console application process doing updates to the list. I thought at first the event receiver would be called in a RPC fashion and would live in the web application process. My mistake :)
    My event receiver is responding to the ItemAdded and ItemUpdated events which are assynchronous. Once the console application ends its processing, it shuts down all the threads created by the event receiver even if they did not ended their work!
    As there is no way to check if the event receiver ran or not in the code, and after searching on the web for a couple of hours, the only way to solve this is to put a Thread.Sleep at the end of the console application in order to let the event receiver thread
    pool threads finish their work and avoid killing them.
    Normally the wait time should not be too long except if the event receiver is really doing an heavy job or suffers of a huge memory leak (sounds familiar... :p)
    Hope this will help others solving their issues.

  • Insert data into Access with Auto-Increment column

    Is there anyone out there that has come across this problem I am experiencing?
    I have a form I'm trying to submit to an Access DB that has an Auto-Incremented Table Column. I have followed Stefan Cameron's instructions to a "T" on his blog page here:
    http://forms.stefcameron.com/2006/09/18/connecting-a-form-to-a-database/
    but I keep getting the following error"
    GeneralError: Operation failed.
    XFAObject.open:10:XFA:form1[0]:mysubform[0]:myEIFform[0]:overflowLeader[0]:Submit[0]:click
    open operation failed. [Microsoft][ODBC Microsoft Access Driver] Number of query values and destination fields are not the same.
    My OLEDB Connection Record Source is the SQL Query which reads: SELECT FedTaxID, LegalID FROM dbtest; My simple test DB is Access and its only 3 columns; dbID, FedTaxID, LegalID. dbID is the Auto-Incremented Column.
    If I remove the Auto column from my DB table it inserts just fine but I get this error:
    GeneralError: Operation failed.
    XFAObject.open:10:XFA:form1[0]:mysubform[0]:myEIFform[0]:overflowLeader[0]:Submit[0]:click
    ado2xfa operation failed. Item cannot be found in the collection corresponding to the requested name or ordinal.
    I've looked over alot of the blogs and other help forums and there's info on Selects, I don't find much on Inserts.
    Can anyone direct me in the right direction? Thank you.

    First, please pay attention to the forum in which you are posting.  This particular post would be more appropriate to tsql rather than datamining.  Second, what specific problem are you trying to solve.  The code you posted appears to be
    correct.  I will say that your DataTable will likely be a source of future problems if it contains only the 2 columns.

  • Insert Nodes in BW Hierarchy

    Hello,
    I want to create ABAP program to insert nodes into a hierarchy.
    I got a class CL_RSSH_HIERMAINTAIN_FRONT with method INSERT_NODES_HIERARCHY .
    But the method is private and cannot be used in the ABAP call.
    I also don't want a pop up which asks for the action on duplicate nodes.
    Can anyone guide me a bit here ?
    Any help would be appreciated.
    Varun

    Christian,
         The attached document would answer most of your questions.
         https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/biw/g-i/how%20to%20plan%20in%20bps%20using%20hierarchies%20with%20several%20characteristics.pdf
        Hope this helps.
    Cheers
    Srini

Maybe you are looking for

  • Tx 2000 tablet PC overheating. HP refuses to help me.

    I have an HP tx 2000 tablet PC with AMD Turion 64 x2 TL-60 2.00 GHz. I am running Windows Vista 32 Bit SP1.  My laptop has been reaching temps of 80 degrees C and sometimes even higher. This is with only one program (IE or Firefox open and running).

  • Help with EasyLink Advisor for WRT54GS

    Ok when I try and bring up the EasyLink Advisor for my router it says Administrator Privileges Required then under that it says You must be logged on as a user with administrator privileges to modify the computer's configuration for home networking.

  • Form F110_IN_CHECK text 510-B missing

    When i run my automatic payment program i get an error message in the prposal log; In form F110_IN_CHECK / window MAIN, the element 510-B (Text-B) is missing. What should i do to correct that error and print my cheque without defects.

  • Connected but nothing else

    Hi, i have a problem with Nokia PC Suite (7.0.8.2) and 5200. When i connect phone to PC, Nokia PC Suite detects it, i can see "Nokia 5200 connected via USB" pop-up. For example i want to manage files - im clicking "Manage files" and... I see explorer

  • Loaded movie is not cropped

    I created a first movie 750 x 235. Objects in this clip are often larger than the final document bascialy sticking out of the scene throughout the movie I then created a second document "main page" that will be hosting the first clip. I created a con