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. Advertisements

  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. Advertisements

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,922
  2. Alexandre Jaquet

    [JTree] Adding a leaf to a node

    Alexandre Jaquet, Nov 8, 2003, in forum: Java
    Replies:
    0
    Views:
    742
    Alexandre Jaquet
    Nov 8, 2003
  3. Alexandre Jaquet

    [JTree] click on a node or a leaf

    Alexandre Jaquet, Nov 10, 2003, in forum: Java
    Replies:
    2
    Views:
    5,395
    Matthew Zimmer
    Nov 11, 2003
  4. Tim
    Replies:
    2
    Views:
    4,762
  5. Tjerk Wolterink
    Replies:
    2
    Views:
    1,726
    Dimitre Novatchev
    Aug 24, 2006
  6. Replies:
    0
    Views:
    623
  7. jumpz
    Replies:
    3
    Views:
    851
    Jean-Baptiste Nizet
    Nov 12, 2007
  8. Replies:
    2
    Views:
    4,683
Loading...