removing node from the JTree

Discussion in 'Java' started by Narayanan Kaleeswaram, Jan 15, 2004.

  1. Hello,
    What I will do for removing and loading another node in the same
    row to the JTree.Adding node to tree is as follows(in ActivateEvent of
    the InternalFrame).
    -------------
    dmtnFun=new DefaultMutableTreeNode(filename);//dmtnFun,
    DefaultMutableTreeNode
    //filename is String
    funTree=new JTree(dmtnFun);//JTree object
    panFun.add(funTree); panFun is a JLabel
    for(int i=0;i<10;1++)
    dmtnFun.add(new DefaultMutableTreeNode(fun)); //fun is a String
    array
    ((DefaultTreeModel)funTree.getModel()).reload(dmtnFun);
    would like to remove this perticlar node(dmtnFun) from the tree in
    DeactivateEvent of the InternalFrame and add new node(dmtnFun) with
    the above code.
     
    Narayanan Kaleeswaram, Jan 15, 2004
    #1
    1. Advertising

  2. Narayanan Kaleeswaram wrote:
    > Hello,
    > What I will do for removing and loading another node in the same
    > row to the JTree.Adding node to tree is as follows(in ActivateEvent of
    > the InternalFrame).
    > -------------
    > dmtnFun=new DefaultMutableTreeNode(filename);//dmtnFun,
    > DefaultMutableTreeNode
    > //filename is String
    > funTree=new JTree(dmtnFun);//JTree object
    > panFun.add(funTree); panFun is a JLabel
    > for(int i=0;i<10;1++)
    > dmtnFun.add(new DefaultMutableTreeNode(fun)); //fun is a String
    > array
    > ((DefaultTreeModel)funTree.getModel()).reload(dmtnFun);
    > would like to remove this perticlar node(dmtnFun) from the tree in
    > DeactivateEvent of the InternalFrame and add new node(dmtnFun) with
    > the above code.



    Provide real code, not this random collection of lines.

    What I can guess from his mess is:

    You are not changing the data via the TreeModel, but you somehow
    mess with the JTree and the individual nodes. Don't do this.
    Also, do not use reload(). The TreeModel methods for inserting and
    removing nodes are supposed to fire the necessary events to the
    JTree. If you use a DefaultTreeModel, this firing is already
    implemented. If you have your own implementaion of TreeModel, you
    are supposed to implement this handling.

    Get a good book about Swing, or at least read the Sun GUI tutorial,
    and the Swing architecture article in Sun's TCS article collection.

    /Thomas
     
    Thomas Weidenfeller, Jan 15, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    1,570
  2. Tjerk Wolterink
    Replies:
    2
    Views:
    1,459
    Dimitre Novatchev
    Aug 24, 2006
  3. Replies:
    0
    Views:
    524
  4. jumpz
    Replies:
    3
    Views:
    634
    Jean-Baptiste Nizet
    Nov 12, 2007
  5. Replies:
    2
    Views:
    4,216
Loading...

Share This Page