jPopupMenu = new JPopupMenu();
            jTree.add(jPopupMenu);
            jTree.addMouseListener(new MouseAdapter()
            {
                  public void mouseReleased(MouseEvent e)
                  {
                        try
                        {
                              //是否右键单击
                              if (e.getClickCount() == 1 && SwingUtilities.isRightMouseButton(e))
                              {
                                    TreePath path = jTree.getPathForLocation(e.getX(), e.getY());
                                    if (path == null)
                                          return;
                                    jTree.setSelectionPath(path);
                                    jPopupMenu.show(jTree, e.getX(), e.getY());
                              }
                              else if (e.getClickCount() == 1)
                              {
                                    TreePath path = jTree.getPathForLocation(e.getX(), e.getY());
                                    if (path == null)
                                          return;
                                    if (jTree.isExpanded(path))
                                    {
                                          jTree.collapsePath(path);
                                    }
                                    else
                                    {
                                          jTree.expandPath(path);
                                    }
                                    return;
                              }
                        }
                        catch (Exception ex)
                        {
                              ex.printStackTrace();
                        }
                  }
            });