Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to change icon of a empty folder in JTree? (FTP File)
    text
    copied!<p>I am working with to show all files and folders of a FTPserver into a JTree. But I got a problem that the empty folders are shown as a file. But how to show them as a folder icon?</p> <p>Here is my code: </p> <pre><code>public void buildTree(){ try { ftpClient.connect("130.229.178.31"); ftpClient.login("admin", "123456"); root = new DefaultMutableTreeNode("Welcome!"); for (int i = 0; i &lt; 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 &amp;&amp; i&lt;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(); } } </code></pre> <p><img src="https://i.stack.imgur.com/7f1F6.jpg" alt="FTP JTree"></p> <p>The "sad" folder is a empty folder, but shown as a file icon. How to change it?</p> <p>Thank you very much</p> <p>PS: Same of the methods is not working, like</p> <pre><code>FileSystemView fileSystemView = FileSystemView.getFileSystemView(); setIcont(fileSystemView.getSystemIcon(File file)); </code></pre> <p>Because we are working with FTP files not with files.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload