Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 7 8 package org.jdesktop.swing.treetable; 9 10 import java.io.File ; 11 import java.util.List ; 12 import java.util.Vector ; 13 14 import javax.swing.tree.DefaultMutableTreeNode ; 15 16 21 public class FileNode extends DefaultMutableTreeNode { 22 public FileNode(File file) { 23 this.file = file; 24 this.isDir = file.isDirectory(); 25 } 26 27 36 37 public boolean getAllowsChildren() { 38 return isDir; 39 } 40 41 protected List getChildren() { if (children == null) { 43 try { 44 final String [] files = file.list(); 45 if (files != null) { 46 children = new Vector (files.length); 48 final String path = file.getPath(); 49 for (int i = 0; i < files.length; i++) { 50 final File childFile = new File (path, files[i]); 51 children.add(new FileNode(childFile)); 52 } 53 } 54 } 55 catch (SecurityException se) { 56 } 57 } 58 59 return children; 60 } 61 62 public File getFile() { 63 return file; 64 } 65 66 public boolean isLeaf() { 67 return !isDir; 68 } 69 70 public String toString() { 71 return file.getName(); 72 } 73 74 private final File file; 75 private final boolean isDir; 76 } 77
| Popular Tags
|