java - JTree expandPath 适用于 File 但不适用于包装类
问题描述
我想知道有什么要求才能JTree
正常工作。我已经编写了一些代码,显示了一个文件系统树,然后调用expandPath()
它来扩展它的路径。
当我使用 File 对象时,一切正常,但树显示每个节点上的完整路径。所以我将它包装在一个更改的类中,toString()
以便只显示目录/文件名,但现在expandPath()
不再工作并且路径没有扩展。
package tools.controls.TreeControl.Filesystem;
import java.io.File;
import java.net.URI;
public class TreeFile
extends File
implements Cloneable
, Comparable<File>
{
private static final long serialVersionUID = 1L;
public TreeFile(TreeFile oOther)
{
super(oOther.getParentFile(), oOther.getName());
}
public TreeFile(File oFile)
{
super(oFile.getParentFile(), oFile.getName());
}
public TreeFile(String oPath)
{
super(oPath);
}
public TreeFile(URI oFileURL)
{
super(oFileURL);
}
public TreeFile(String oParent, String oChild)
{
super(oParent, oChild);
}
public TreeFile(File oParent, String oChild)
{
super(oParent, oChild);
}
public TreeFile getParentTreeFile()
{
File f = getParentFile();
if(f == null)
return null;
return new TreeFile(f);
}
public String toString()
{
return getName();
}
public TreeFile clone()
{
return new TreeFile(this);
}
@Override
public int compareTo(File oObject)
{
return super.compareTo(oObject);
}
}
解决方案
推荐阅读
- c# - 合并排序函数C#不排序
- php - 使用 PHP 计算数据库中每列值的出现次数
- java - 如何对字段错误列表和一组 ConstraintViolation 进行排序?
- php - 如何使php mvc动态url
- android - 如何创建双重关系房间
- postgresql - SQLAlchemy:如何正确转义 .update() 的文本
- python - python如何对treeview列中的所有数字求和
- javascript - 在由 Storage 触发的 Google Cloud 函数中提供上下文
- python - 动画子图
- javascript - 在数据表中使用 ajax 函数加载数据时,只有整数值的 int 列的排序函数不起作用