Article View: borland.public.jbuilder.java.swing
Article #1143Re: adding a node to a JTree
From: Alan Shiers
Date: Tue, 16 Mar 2004 23:56
Date: Tue, 16 Mar 2004 23:56
60 lines
3001 bytes
3001 bytes
Hi Paul,
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?
How do I select a node programmatically using a TreePath object?
Alan
"Paul Furbacher [TeamB]" <pfurbacher@mac.com> wrote in message
news:40577f00@newsgroups.borland.com...
> Alan Shiers wrote:
>
> > [...].
> >
> > My main problem, I am discovering, is that the main JTree on the main
> > interface doesn't receive an actual click of the node from the mouse,
> > thereby not triggering a TreeSelectionEvent as apposed to when I try to
> > delete a node. So, [...]
>
> JTree has methods for translating x,y into rows, path, etc.
> The mouse event which pops up your menu gives you x and y.
> Pass those values into your method. I think that should
> solve your problem.
>
> >>public void createLeafNode(int x, int y)
> >> {
> >> //jTree1.repaint();
>
> TreePath path = jTree1.getPathForLocation(x, y);
>
> >> if(path == null)
> >> return;
> >>[...]
> >> }
>
>
> --
>
>
> 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:
<405793e6$2@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!crtntx1-snh1.gtei.net!news.gtei.net!newsfeed1.easynews.com!easynews.com!easynews!newshosting.com!nx01.iad01.newshosting.com!203.109.252.33.MISMATCH!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>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-16 16:04:53 PST From: "Alan Shiers" <ashiers@hfx.eastlink.ca> Newsgroups: borland.public.jbuilder.java.swing References: <40564bf4@newsgroups.borland.com> <405752b0@newsgroups.borland.com> <40577f00@newsgroups.borland.com> Subject: Re: adding a node to a JTree Date: Tue, 16 Mar 2004 19:56:00 -0400 Lines: 62 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 24.222.101.2 Message-ID: <405793e6$2@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1079481318 24.222.101.2 (16 Mar 2004 15:55:18 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!crtntx1-snh1.gtei.net!news.gtei.net!newsfeed1.easynews.com!easynews.com!easynews!newshosting.com!nx01.iad01.newshosting.com!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail