Java 如何更改JTree中空文件夹的图标?(FTP文件)
我正在使用将FTPserver的所有文件和文件夹显示到JTree中。但是我遇到了一个问题,空文件夹显示为一个文件。但是如何将它们显示为文件夹图标呢 这是我的密码:Java 如何更改JTree中空文件夹的图标?(FTP文件),java,ftp,icons,jtree,Java,Ftp,Icons,Jtree,我正在使用将FTPserver的所有文件和文件夹显示到JTree中。但是我遇到了一个问题,空文件夹显示为一个文件。但是如何将它们显示为文件夹图标呢 这是我的密码: public void buildTree(){ try { ftpClient.connect("130.229.178.31"); ftpClient.login("admin", "123456"); root = new DefaultMut
public void buildTree(){
try {
ftpClient.connect("130.229.178.31");
ftpClient.login("admin", "123456");
root = new DefaultMutableTreeNode("Welcome!");
for (int i = 0; i < 1; i++) {
DefaultMutableTreeNode temp = new DefaultMutableTreeNode("FTP-Server");
root.add(temp);
bind(temp,"");
}
} catch (IOException e1) {
e1.printStackTrace();
throw new RuntimeException("Client Error", e1);
}
try {
ftpClient.disconnect();
} catch (IOException e2) {
e2.printStackTrace();
throw new RuntimeException("Error when shutdown", e2);
}
}
// bind nod/subnode to the tree (recursive method)
public void bind(DefaultMutableTreeNode node,String path){
try {
Boolean defaultPath = true;
while (defaultPath)
{
defaultPath = ftpClient.changeToParentDirectory();
}
ftpClient.changeWorkingDirectory(path);
FTPFile[] files = ftpClient.listFiles();
for(int i=0;files!=null && i<files.length;i++){
FTPFile tempFile = files[i];
if(tempFile.isDirectory()){
DefaultMutableTreeNode tempNode = new DefaultMutableTreeNode(tempFile.getName());
node.add(tempNode);
bind(tempNode, path+"/"+tempFile.getName());
}else{
DefaultMutableTreeNode tempNode = new DefaultMutableTreeNode(tempFile.getName());
node.add(tempNode);
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
因为我们使用的是FTP文件,而不是文件。您有两个选择:
- 将“虚拟文件”添加到空文件夹(可能称之为“[空]”)或
- 用你自己的
- 将“虚拟文件”添加到空文件夹(可能称之为“[空]”)或
- 用你自己的
FileSystemView fileSystemView = FileSystemView.getFileSystemView();
setIcont(fileSystemView.getSystemIcon(File file));