我需要在Panel
中嵌入JFileChooser
对话框。我只需要文件和文件夹 View 。如何禁用 dialogBox
中包含的其他面板,即来自 JFileChooser()
dialogBox
的(文件操作、文件选择和过滤器面板)..
谢谢
最佳答案
您可能想考虑使用JTree
显示文件结构。
将 File 结构转换为 TreeModel
的实现相当容易。 .
基本上,我会首先创建一个名为 FileTreeModel
的类。
然后,您可以使用顶级目录作为模型的根目录并从那里开始。
然后,您所需要做的就是将 JTree
的 TreeModel
设置为 FileTreeModel
的 TreeModel
。
FileTreeModel
的代码可能如下所示:
private File root;
public TreeModel(File root){
this.root = root;
}
public boolean isLeaf(Object node){
File f = (File) node;
return !f.isDirectory();
}
您将需要实现接口(interface)的其余部分。但这相当简单。
关于java - 如何从 JFileChooser(JAVA Swing) 禁用文件操作、文件选择和过滤面板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/796946/