Article View: borland.public.jbuilder.java.swing
Article #7968Re: JTree trouble deleting nodes
From: Michael Rachow
Date: Fri, 17 Nov 2000 00:00
Date: Fri, 17 Nov 2000 00:00
23 lines
1244 bytes
1244 bytes
Hi Jolene,
If you are removing the node inside the TreeSelectionListener, maybe this
helps:
DefaultTreeModel dtm = (DefaultTreeModel)yourTree.getModel();
DefaultMutableTreeNode dmtm =
(DefaultMutableTreeNode)yourTree.getLastSelectedPathComponent();
yourTree.setSelectionRow(yourTree.getMinSelectionRow() - 1); // Or better
dtm.removeNodeFromParent(dmtm);
dtm.nodesWereRemoved((TreeNode)dmtm,new int[]{},new Object[]{});
There is one tricky thing.
removeNodeFromParent invokes the TreeSelectionListener again, so one have to
take
care, that at this time nothing had to be done with the already deleted
node.
So the sequence of the statements above is NOT a recommendation.
Greetings
Michael
Technical Details
Message-ID:
<3a14e70c_2@dnews>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<8uuh6u$p2h$1@linux.mers.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,9c9054d0059a43f X-Google-Attributes: gid111d45,public From: "Michael Rachow" <mrachow@BeraCom.de> Subject: Re: JTree trouble deleting nodes Date: 2000/11/17 Message-ID: <3a14e70c_2@dnews> X-Deja-AN: 694649632 References: <8uuh6u$p2h$1@linux.mers.com> X-Trace: 17 Nov 2000 00:06:36 -0800, 62.158.178.40 X-MSMail-Priority: Normal X-Priority: 3 Newsgroups: borland.public.jbuilder.java.swing X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400