Results 1 to 14 of 14

Thread: JTree and FTP

  1. #1
    Alexis is offline Member
    Join Date
    Nov 2010
    Posts
    17
    Rep Power
    0

    Default JTree and FTP

    Hello . I am trying to set a ftp list into jtree but jtree appears empty . Here is my code

    Java Code:
    import java.io.IOException;
    import java.net.SocketException;
    import java.util.*;
    
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JTree;
    
    import org.apache.commons.net.ftp.*;
    
    public class FTPTest 
    {
    	public static void main(String[] args) throws SocketException, IOException 
    	{
    		JFrame fr=new JFrame("Swing Frame");
    		fr.setSize(800,600);
    		JPanel panel = new JPanel();
    		panel.setLayout(null);
    		
    		String server = "server_ip";
    		String username = "id";
    		String password = "pass";
    		FTPClient client = new FTPClient();
    		
    		client.connect(server);
    		client.login(username, password);
    		String[] files = client.listNames();
    			
    		Hashtable hash = new Hashtable();
    			
    		for(int i = 0; i < files.length; i++) 
    		{
    			hash.put("Server",files[i]);
    			System.out.println(files[i]);
    		}		
    		
    		JTree tree = new JTree(hash);
    		client.disconnect();
    			
    		fr.add(panel);
    		panel.add(tree);
    		tree.setLocation(350,100);
    		tree.setSize(300,400);
    		fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);;
    		fr.setLocationRelativeTo(null);
    		fr.setVisible(true);
    
    	}
    }

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,585
    Rep Power
    25

    Default

    Is anything returned by the listNames() method?
    Are there any error codes?

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,585
    Rep Power
    25

    Default

    Is anything returned by the listNames() method?
    Are there any error codes?

  4. #4
    Alexis is offline Member
    Join Date
    Nov 2010
    Posts
    17
    Rep Power
    0

    Default

    When i run the program ( i use eclipse IDE )
    Gui appears normally . With empty JTree .

    At console ( eclipse ) the files list , appears normally too .


    No errors .

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,585
    Rep Power
    25

    Default

    If the FTP code returns a good list of data, then your problem is with adding that list to the JTree.

    Print out the contents of the hashtable to see what will be added to the tree:
    System.out.println("hash=" + hash); // show the contents
    Last edited by Norm; 06-27-2011 at 05:07 PM.

  6. #6
    Alexis is offline Member
    Join Date
    Nov 2010
    Posts
    17
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    If the FTP code returns a good list of data, then your problem is with adding that list to the JTree.

    Print out the contents of the hashtable to see what will be added to the tree:
    System.out.println("hash=" + hash); // show the contents
    That is my problem Any help on who can i adding the list in JTree ;;;;;;;;


    (the FTP code returns a good list of data)

  7. #7
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,585
    Rep Power
    25

    Default

    What is printed out using the println I posted?

  8. #8
    Alexis is offline Member
    Join Date
    Nov 2010
    Posts
    17
    Rep Power
    0

    Default

    I'm sorry ,


    hash={Server=Desktop}
    hash={Server=testcheckout}
    hash={Server=workspace}
    hash={Server=Downloads}

  9. #9
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,585
    Rep Power
    25

    Default

    Did you print that inside the loop or outside the loop just before the new JTree(hash) call?
    Move it outside of the loop and see what is in the hashtable just before calling JTree

  10. #10
    Alexis is offline Member
    Join Date
    Nov 2010
    Posts
    17
    Rep Power
    0

    Default

    If i move it out of the loop it displays only
    hash={Server=Downloads}

  11. #11
    Alexis is offline Member
    Join Date
    Nov 2010
    Posts
    17
    Rep Power
    0

    Default

    I change the
    hash.put("Server", files[i]); to
    hash.put("Server", files);

    and both files and folders appears like files . Any ideas ????
    ( Downloads is file not folder )

  12. #12
    Alexis is offline Member
    Join Date
    Nov 2010
    Posts
    17
    Rep Power
    0

    Default

    I change the
    hash.put("Server", files[i]); to
    hash.put("Server", files);

    and both files and folders appears like files . Any ideas ????
    ( Downloads is file not folder )

  13. #13
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,585
    Rep Power
    25

    Default

    hash={Server=Downloads}
    What does that tell you about what is in the hashtable? It looks like it has only one entry. And that is the same as the last item added to the hashtable.

    Read the API doc for the Hashtable class and consider what the key values should be.

  14. #14
    Alexis is offline Member
    Join Date
    Nov 2010
    Posts
    17
    Rep Power
    0

Similar Threads

  1. Jtree
    By yoga in forum AWT / Swing
    Replies: 1
    Last Post: 02-09-2011, 03:21 PM
  2. Jtree
    By yoga in forum AWT / Swing
    Replies: 0
    Last Post: 02-09-2011, 09:31 AM
  3. Jtree Help
    By miladirooni in forum New To Java
    Replies: 1
    Last Post: 10-28-2009, 12:00 AM
  4. zip to JTree
    By icsbcn in forum AWT / Swing
    Replies: 8
    Last Post: 09-01-2009, 04:26 PM
  5. Move JTree item to another JTree.
    By Melki in forum AWT / Swing
    Replies: 8
    Last Post: 07-09-2009, 11:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •