Article View: borland.public.jbuilder.java.swing
Article #10150Re: No really, I still like JTrees...
From: Tad Frysinger
Date: Thu, 11 Nov 1999 00:00
Date: Thu, 11 Nov 1999 00:00
59 lines
2652 bytes
2652 bytes
Try this:
jTree1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e)
{
if ( e.getClickCount() == 2 )
jTree1_mouseClicked(e);
}
});
void jTree1_mouseClicked(MouseEvent e)
{
TreePath path = dataTree.getPathForLocation(e.getX(), e.getY());
if ( path != null )
{
// check selection, if not there move it, etc.
}
}
Jeff Marendo wrote:
> I'm trying to create a class that I can use to handle double-click events
> generated by a mouse on my JTree. What I want to do is open certain panels
> depending on the string value that a target node holds. One of my problems
> is that I'm not sure how I need to associate the mouseClicked event I'm
> making in my mouse listener class with a TreeSelectionEvent variable (to
> identify where I'm currently at in the tree). This is how I'm defining my
> mouse listener class, but I know I'm missing a big piece of the puzzle with
> regards to TreeSelectionListener and TreeSelectionEvent:
>
> // Define a class that can be used for double-clicking events within the
> tree.
> class DoubleClickedMouseListener extends MouseAdapter {
> public void mouseClicked(MouseEvent me) {
> if(me.getClickCount() == 2)
> {
> TreeSelectionEvent event = ???; // I had 'null' here just to
> initialize it, but that was very wrong.
> TreePath path = event.getPath();
> String nodeName = path.getLastPathComponent().toString();
> // getReport(nodeName);
> System.out.println("You double-clicked: " + nodeName);
> }
> }
> }
>
> Down in my code where I'm creating all of my JTree nodes:
>
> MouseAdapter dblClickedListener =
> new DoubleClickedMouseListener();
>
> if(dblClickedListener != null)
> jTree1.addMouseListener (dblClickedListener);
>
> Can anyone see where I'm going wrong with this? Thanks in advance.
>
> Jeff
Technical Details
Message-ID:
<382ACD4A.CBBCDDBD@earthlink.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<809rjs$p3r15@forums.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,795280df6ee112a7 X-Google-Attributes: gid111d45,public From: Tad Frysinger <tfrysinger@earthlink.net> Subject: Re: No really, I still like JTrees... Date: 1999/11/11 Message-ID: <382ACD4A.CBBCDDBD@earthlink.net> X-Deja-AN: 547328753 Content-Transfer-Encoding: 7bit References: <809rjs$p3r15@forums.borland.com> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: Another Netscape Collabra Server User Mime-Version: 1.0 Reply-To: tfrysinger@earthlink.net Newsgroups: borland.public.jbuilder.java.swing