swing的路径选择
来源:百度知道 编辑:UC知道 时间:2024/04/28 22:33:27
public class FileTree extends JTree {
public FileTree(String path)
throws FileNotFoundException, SecurityException {
super((TreeModel) null);// Create the JTree itself
// Use horizontal and vertical lines
putClientProperty("JTree.lineStyle", "Angled");
// Create the first node
FileTreeNode rootNode = new FileTreeNode(null, path);
// Populate the root node with its subdirectories
boolean addedNodes = rootNode.populateDirectories(true);
setModel(new DefaultTreeModel(rootNode));
// Listen for Tree Selection Events
addTreeExpansionListener(new TreeExpansionHandler());
}
// Returns the full pathname for a path, or null
// if not a known path
public String getPathName(TreePath path) {
Object o = path.getLastPathComponent();
if