TreeNode last = null;
Object last = null;
		public void keyPressed(KeyEvent e)		{         TreePath start = BasicTreeUI.this.tree.getLeadSelectionPath();      TreeNode last = null;         if (start != null)        last = (TreeNode) start.getLastPathComponent();         if (last != null)         {            // DOWN, KP_DOWN            if (e.getKeyCode() == KeyEvent.VK_DOWN                  || e.getKeyCode() == KeyEvent.VK_KP_DOWN)            {              TreeNode next = (TreeNode) BasicTreeUI.this.              getNextVisibleNode(last);               if (next != null)               {                  TreePath newPath = new TreePath(getPathToRoot(next, 0));                  BasicTreeUI.this.selectPath(BasicTreeUI.this.tree, newPath);                  if (e.isControlDown())                     tree.setLeadSelectionPath(newPath);                  else if (!next.isLeaf() && e.isShiftDown())                  {                     BasicTreeUI.this.tree.expandPath(newPath);                     BasicTreeUI.this.tree.fireTreeExpanded(newPath);                  }               }            }            // UP, KP_UP            else if (e.getKeyCode() == KeyEvent.VK_UP                  || e.getKeyCode() == KeyEvent.VK_KP_UP)            {              TreeNode prev = (TreeNode) BasicTreeUI.this.              getPreviousVisibleNode(last);                        if (prev != null)               {                  TreePath newPath = new TreePath(getPathToRoot(prev, 0));               BasicTreeUI.this.selectPath(BasicTreeUI.this.tree,                                              new TreePath(getPathToRoot(prev, 0)));                  if (e.isControlDown())                     tree.setLeadSelectionPath(newPath);                  else if (!prev.isLeaf() && e.isShiftDown())                  {                     BasicTreeUI.this.tree.expandPath(newPath);                     BasicTreeUI.this.tree.fireTreeExpanded(newPath);                  }            }            }            // LEFT, KP_LEFT            else if (e.getKeyCode() == KeyEvent.VK_LEFT                  || e.getKeyCode() == KeyEvent.VK_KP_LEFT)            {              TreePath path = new TreePath(getPathToRoot(last, 0));              TreeNode p = last.getParent();                              if (!last.isLeaf() && BasicTreeUI.this.tree.isExpanded(path))               {                  BasicTreeUI.this.tree.collapsePath(path);                  BasicTreeUI.this.tree.fireTreeCollapsed(path);               }               else if (p != null)                  BasicTreeUI.this.selectPath(BasicTreeUI.this.tree,                                            new TreePath(getPathToRoot(p, 0)));            }            // RIGHT, KP_RIGHT            else if (e.getKeyCode() == KeyEvent.VK_RIGHT                  || e.getKeyCode() == KeyEvent.VK_KP_RIGHT)            {              TreePath path = new TreePath(getPathToRoot(last, 0));                  if (!last.isLeaf() && BasicTreeUI.this.tree.isCollapsed(path))               {                  BasicTreeUI.this.tree.expandPath(path);                  BasicTreeUI.this.tree.fireTreeExpanded(path);               }               else               {                  TreeNode next = (TreeNode) BasicTreeUI.this.                  getNextVisibleNode(last);                  if (next != null)                     BasicTreeUI.this.selectPath(BasicTreeUI.this.tree,                                                new TreePath(getPathToRoot(next, 0)));               }            }            // Enter            else if (e.getKeyCode() == KeyEvent.VK_ENTER)            {              TreePath path = new TreePath(getPathToRoot(last, 0));               if (!last.isLeaf())               {                  if (BasicTreeUI.this.tree.isExpanded(path))                  {                     BasicTreeUI.this.tree.collapsePath(path);                     BasicTreeUI.this.tree.fireTreeCollapsed(path);                  }                  else                  {                     BasicTreeUI.this.tree.expandPath(path);                     BasicTreeUI.this.tree.fireTreeExpanded(path);                  }               }            }         }		}