Article View: borland.public.jbuilder.java.swing
Article #1146Re: adding a node to a JTree
From: Paul Furbacher [TeamB]
Date: Wed, 17 Mar 2004 13:34
Date: Wed, 17 Mar 2004 13:34
64 lines
3270 bytes
3270 bytes
Alan Shiers wrote:
> I think you misunderstand my problem. I have no problem creating a TreePath
> object as the SaveAs dialog box, which has a duplicatate JTree structure
> (directories only), produces one for me upon selection of a node in the
> JTree of the SaveAs dialog box. I then pass this TreePath object to an
> instance variable into another class to hold. At no time have I actually
> clicked on a node of the JTree on the main interface. I have only the
> TreePath object and need to use that to signal to JTree on main interface to
> select the node specified by the TreePath object.
>
> Now, do you see?
Yes, I see that I misread it. I was incorrectly
thinking that there was a mouse event related
to some popup which your methods weren't receiving.
Got it now.
> How do I select a node programmatically using a TreePath object?
There are some unknowns here, so I'm going
to do some guessing.
If I browse JFileChooser, I don't find
any reference to "treepath". Are we dealing
with a Save As dialog of your own crafting?
Also, I notice that you commented out
jTree1.setSelectionPath(path);
Is that because that didn't select anything,
contrary to what you expected? If so, that
leads me to think that the tree path which
you get back from the dialog is not filled
with the same node objects as the ones in
the tree you are trying to maintain. And if
that is the case, my guess is that you
will have to walk the tree, starting at the
root, asking for a child iterator/enumerator
for the node, and asking each node what it's
user object is, and then comparing the value
of importance for a match.
treepath.getPath()
gives you an array. You can use that to compare
to each node as you iterate through each level.
--
Paul Furbacher (TeamB)
Save time, search the archives:
http://www.borland.com/newsgroups/ngsearch.html
Is it in Joi Ellis's Faq-O-Matic?
http://www.visi.com/~gyles19/fom-serve/cache/1.html
Finally, please send responses to the newsgroup only.
That means, do not send email directly to me.
Thank you.
Technical Details
Message-ID:
<405853df$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<40564bf4@newsgroups.borland.com> <405752b0@newsgroups.borland.com> <40577f00@newsgroups.borland.com> <405793e6$2@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,a760aeb930adb421 X-Google-Attributes: gid111d45,public X-Google-ArrivalTime: 2004-03-17 05:39:19 PST Date: Wed, 17 Mar 2004 08:34:24 -0500 From: "Paul Furbacher [TeamB]" <pfurbacher@mac.com> Organization: Reverse Alchemy, Inc. User-Agent: Mozilla Thunderbird 0.5 (Macintosh/20040208) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.jbuilder.java.swing Subject: Re: adding a node to a JTree References: <40564bf4@newsgroups.borland.com> <405752b0@newsgroups.borland.com> <40577f00@newsgroups.borland.com> <405793e6$2@newsgroups.borland.com> In-Reply-To: <405793e6$2@newsgroups.borland.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 68.39.103.120 Message-ID: <405853df$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1079530463 68.39.103.120 (17 Mar 2004 05:34:23 -0800) Lines: 64 Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail