JTree and dropdown options on right clicking nodes

前端 未结 3 1231
醉话见心
醉话见心 2021-01-15 01:49

I\'m trying to use the JTree and implement different drop downs for all the parent nodes and the children nodes.

Here\'s what I\'ve done:

pmTree.addM         


        
3条回答
  •  暖寄归人
    2021-01-15 02:16

    Awesome. I was successfully able to put the setSelectionPath() call inside the override of getPopupLocaiton(). I had been trying to do it inside the ActionListener of my JMenuItem to no avail.

    public Point getPopupLocation( MouseEvent e ) {
        Point point = null;
        if( e != null ) {
            TreePath path = getClosestPathForLocation( e.getX(), e.getY() );
            setSelectionPath( path );
            point = e.getPoint();
        }
        return point;
    }
    

提交回复
热议问题