swing的路径选择

来源:百度知道 编辑:UC知道 时间:2024/04/28 22:33:27
请问,除了JFileChooser,还有什么方法可以得到本地的路径,树状的可选路径,而不是像 JFileChooser那样的选择对话框,类似于图片中,谢谢了

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