Hi Alberto,

Swing's tree already consumes the double click gesture for non leaf nodes: the node collapses / expands. Therefore the ULCTree only reacts on double clicks on leaf nodes to prevent double actions on non leaf nodes.

However, if you wish to have action events on non leaf nodes you can use the snippet at the end of my mail.

Regards Dany



import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.SwingUtilities;
import javax.swing.tree.TreePath;

import com.ulcjava.base.application.AbstractApplication;
import com.ulcjava.base.application.ULCFrame;
import com.ulcjava.base.application.ULCScrollPane;
import com.ulcjava.base.application.ULCTree;
import com.ulcjava.base.application.event.ActionEvent;
import com.ulcjava.base.application.event.IActionListener;
import com.ulcjava.base.client.UITree;
import com.ulcjava.base.development.DevelopmentRunner;

public class TreeActionOnNonLeafSnippet extends AbstractApplication {
   public void start() {
       ULCSnippetTree tree = new ULCSnippetTree();
       tree.addActionListener(new IActionListener() {
           public void actionPerformed(ActionEvent event) {
               System.out.println("Action!");
           }
       });

       ULCFrame frame = new ULCFrame("Snippet");
       frame.setDefaultCloseOperation(ULCFrame.TERMINATE_ON_CLOSE);
       frame.getContentPane().add(new ULCScrollPane(tree));
       frame.pack();
       frame.setVisible(true);
   }

   public static void main(String[] args) {
DevelopmentRunner.setApplicationClass(TreeActionOnNonLeafSnippet.class);
       DevelopmentRunner.main(args);
   }

   public static class ULCSnippetTree extends ULCTree {
       protected String typeString() {
           return UISnippetTree.class.getName();
       }
   }

   public static class UISnippetTree extends UITree {
       protected void postInitializeState() {
           super.postInitializeState();

           ActionHandler actionHandler = new ActionHandler();
           getBasicTree().addMouseListener(actionHandler);
       }

       private class ActionHandler extends MouseAdapter {
           public void mousePressed(MouseEvent event) {
               if (isEnabled() && event.getClickCount() == 2
                       && SwingUtilities.isLeftMouseButton(event)) {
TreePath clickedPath = getBasicTree().getPathForLocation(
                           event.getX(), event.getY());
                   if (clickedPath != null
                           && !getBasicTree().getModel().isLeaf(
                                   clickedPath.getLastPathComponent())) {
                       fireActionPerformedULC(null, event.getModifiers());
                   }
               }
           }
       }
   }
}



Alberto Smulders wrote:
Hi,
Double clicking on a node other than a leaf node in an ULCTree doesn't fire an ActionEvent, only expands/contracts the tree branch. But pushing the Enter key while being selected such a node fires an ActionEvent. Is there a way to get notified of double clicking a node other than leaf nodes? Kind regards, Alberto A.Smulders
HostDat Lda. - Portugal

_______________________________________________
ULC-developer mailing list
[email protected]
http://lists.canoo.com/mailman/listinfo/ulc-developer

Reply via email to