나는 JTree
이 뭔가를 바탕 화면보기를 얻을 싶습니다 Java에 이르기까지,이를 달성하기위한 어려움을 찾아야합니다.바탕 화면보기 Windows에만
public class FileTreeDemo {
public static void main(String[] args) {
File root;
if (args.length > 0) {
root = new File(args[0]);
} else {
root = new File(System.getProperty("user.home"));
}
System.out.println(root);
FileTreeModel model = new FileTreeModel(root);
JTree tree = new JTree();
tree.setModel(model);
tree.setRootVisible(true);
tree.setShowsRootHandles(true);
JScrollPane scrollpane = new JScrollPane(tree);
JFrame frame = new JFrame("FileTreeDemo");
frame.getContentPane().add(scrollpane, "Center");
frame.setSize(400,600);
frame.setVisible(true);
}
}
class FileTreeModel implements TreeModel {
protected File root;
public FileTreeModel(File root) { this.root = root; }
public Object getRoot() { return root; }
public boolean isLeaf(Object node) { return ((File)node).isFile(); }
public int getChildCount(Object parent) {
String[] children = ((File)parent).list();
if (children == null) return 0;
return children.length;
}
public Object getChild(Object parent, int index) {
String[] children = ((File)parent).list();
if ((children == null) || (index >= children.length)) return null;
return new File((File) parent, children[index]);
}
public int getIndexOfChild(Object parent, Object child) {
String[] children = ((File)parent).list();
if (children == null) return -1;
String childname = ((File)child).getName();
for(int i = 0; i < children.length; i++) {
if (childname.equals(children[i])) return i;
}
return -1;
}
public void valueForPathChanged(TreePath path, Object newvalue) {}
public void addTreeModelListener(TreeModelListener l) {}
public void removeTreeModelListener(TreeModelListener l) {}
}
지금까지 내가 변경 시도 FileTreeModel 클래스 '시스템 등록 정보'가 있지만 작동하지 않았다 :
다음 지금까지 내 코드입니다"user.dir"
제발 어떤 방향을 보여줘 보여줘. 고마워.
또한 [File Browser GUI] (http://codereview.stackexchange.com/q/4446/7784)를 참조하십시오. –