你的代码只改变了树,没见操作Jlist啊

解决方案 »

  1.   

    我自己解决了,代码如下:
    DefaultTreeModel model = (DefaultTreeModel) m_treeFile.getModel();
                //explore tree's first layer
                if (!filenode.isExplored()) {
                  File[] filelist = filenode.getFile().listFiles(filter);
                  for (int i = 0; i < filelist.length; i++) {
                    if (filelist[i].isDirectory()) {
                      Filenode node = new Filenode(filelist[i]);
                      model.insertNodeInto(node, filenode, filenode.getChildCount());
                      m_treeFile.scrollPathToVisible(new TreePath(node.getPath()));
                    }
                  }              filenode.setExplored(true);
                }
                else
                {
                  m_treeFile.expandPath(m_treeFile.getSelectionPath());
                }            //explore tree's second layer
                Enumeration enum = filenode.children();
                if(enum==null)
                {
                   m_treeFile.setSelectionPath(new TreePath(filenode.getPath()));
                   return;
                }
                Filenode childnode = null;
                do {
                  childnode = (Filenode) enum.nextElement();
                }
                while (childnode.getFile().getName().compareTo(name) != 0);
                if (childnode.isExplored()) {
                 m_treeFile.setSelectionPath(new TreePath(childnode.getPath()));
                 return;
                }            if (childnode == null) {
                  m_treeFile.setSelectionPath(new TreePath(filenode.getPath()));
                  return;
                }
                File[] childfilelist = childnode.getFile().listFiles(filter);
                if(childfilelist==null)
                {
                  m_treeFile.setSelectionPath(new TreePath(childnode.getPath()));
                  return;
                }
                for (int j = 0; j < childfilelist.length; j++) {
                  if (childfilelist[j].isDirectory()) {
                    Filenode node = new Filenode(childfilelist[j]);
                    model.insertNodeInto(node, childnode, childnode.getChildCount());
                    m_treeFile.scrollPathToVisible(new TreePath(node.getPath()));
                  }
                }
                childnode.setExplored(true);
                m_treeFile.setSelectionPath(new TreePath(childnode.getPath()));          }
            }