double click in a jtree

Discussion in 'Java' started by Christophe Boutin, Jul 24, 2003.

  1. how to get or what is the event to get the double click on a node of a jtree
    i want to add node after a double click
     
    Christophe Boutin, Jul 24, 2003
    #1
    1. Advertising

  2. Register a MouseListener with your JTree, and when you receive a MouseEvent
    check whether getClickCount() == 2

    The JTree is just one component, so you don't register listeners on the
    nodes themselves.
    Seems like the JavaDoc for JTree already has it covered:
    If you are interested in detecting either double-click events or when a user
    clicks on a node, regardless of whether or not it was selected, we recommend
    you do the following:

    final JTree tree = ...;

    MouseListener ml = new MouseAdapter() {
    public void mousePressed(MouseEvent e) {
    int selRow = tree.getRowForLocation(e.getX(), e.getY());
    TreePath selPath = tree.getPathForLocation(e.getX(), e.getY());
    if(selRow != -1) {
    if(e.getClickCount() == 1) {
    mySingleClick(selRow, selPath);
    }
    else if(e.getClickCount() == 2) {
    myDoubleClick(selRow, selPath);
    }
    }
    }
    };
    tree.addMouseListener(ml);


    Simon

    --
    www.catalysoft.com - increasing the rate of your software development


    "Christophe Boutin" <> wrote in message
    news:bfouf0$h2l$...
    > how to get or what is the event to get the double click on a node of a

    jtree
    > i want to add node after a double click
    >
    >
     
    catalysoft.com, Jul 25, 2003
    #2
    1. Advertising

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. Alexandre Jaquet

    [JTree] click on a node or a leaf

    Alexandre Jaquet, Nov 10, 2003, in forum: Java
    Replies:
    2
    Views:
    4,718
    Matthew Zimmer
    Nov 11, 2003
  2. Replies:
    1
    Views:
    6,101
    Vova Reznik
    May 4, 2006
  3. Sydex
    Replies:
    12
    Views:
    6,646
    Victor Bazarov
    Feb 17, 2005
  4. Replies:
    0
    Views:
    394
  5. jumpz
    Replies:
    3
    Views:
    649
    Jean-Baptiste Nizet
    Nov 12, 2007
Loading...

Share This Page