Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8878889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:49:18+00:00 2026-06-14T19:49:18+00:00

I have written a client and server application who are connected with sockets .

  • 0

I have written a client and server application who are connected with sockets.
The server is multithreaded and can hold more than one client.

Now am i using in my client application a jTree model, and on my server i have a folder with fictitious project folders and files in it.
First this application only was client sided with a database on a server, now i want it to fully operate over a socket connection.

The only problem is that the jTree model is created on the server. So when the program starts the client asks the server to create a jTree model of the project folder the user will use in the client application with its files in it.

The Server will send a respone with a jTree model in it and the client puts this model in the jTree swing component.
The jTree is succesfully shown to the user (so the Tree model is succesfully sended over the socket connection), but when the user wants to expand the first projectfolder map: the jTree shows for example: ‘testProject’ as folder.
And for example the folder testProject contains some files:

  • testProject.exe
  • bin
    • test.java
    • test2.java
  • src

As you see in the above example the jTree should show the above tree to the user when the user double clicks on ‘testProject’ in the jTree.

Now my problem

I think the problem is that the server only creates the model of the first folder.
Like it only sends a model with ‘projectFolder’ in it.
But i want the above structure send to the user so the user can use the jTree to download the files from the server. (something i will implement later).

How can i get a full model from the server, that the jTree can show a full model to the user with the projectfolder and all his files.

To make everything a little more clear:

My code

This fragment of code i use on my client to invoke the method that created the jTree model on the server.

public ProjectTreeModel getTreeModel(String projectName) throws ClassNotFoundException {
    try {
        //Creating empty object to invoke te mehod on the server.
        paramObject parameters = new paramObject();
        parameters.string1 = projectName;

        //Creating package to invoke the right method on the server.
        Packet data = new Packet("treemodel.GetModel",parameters);

        //sends in this case an empty object to the server and invokes the treemodel.GetModel method on the server.
        oos.writeObject(data);
        oos.flush();

        ProjectTreeModel model = (ProjectTreeModel) ois.readObject();

        return model;

    } catch (IOException ex) {
        ex.printStackTrace();
    }

    return null;
}

This piece of code i use on the server to create the projectModel and send it back as object to the client to return it as a jTree model in the previous code example.

if(data.getMethod().equals("treemodel.GetModel")) 
         { 
             //in this example i don't use this object, just ignore it.
             paramObject parameters = (paramObject) data.getObject();


             //Extract the information from User
             String projectName = parameters.string1;

             ProjectTreeModel treemodel = new ProjectTreeModel();
             treemodel.newRootPath(projectName);



             oos.writeObject(treemodel);
             output.flush();
             form.sendOutput("ProjectTreeModel succesfully sended to: " + Email);
         }

And at last this is how i create the TreeModel.

import java.io.File;
import java.io.Serializable;
import javax.swing.event.TreeModelListener;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;


public class ProjectTreeModel implements TreeModel, Serializable
{
File f;
private static String rootPath = "src/authorsystem/Projects";

public static void newRootPath(String newRoot)
{
    String desktopPath = System.getProperty("user.home") + "\\Desktop";
    desktopPath.replace("\\", "/");
    rootPath = desktopPath + "\\projectfolders";
}

@Override
public Object getRoot() {
    //userName = LogInForm.ingelogt;

    f = new File(rootPath);
    return f;
}

@Override
public Object getChild(Object parent, int index) {
    File pathName = (File) parent;
    String[] fileNames = pathName.list();
    return new File(pathName.getPath(), fileNames[index]);
}

@Override
public int getChildCount(Object parent) {
    File pathName = (File) parent;
    if(pathName.list() != null)
    {
        String[] fileNames = pathName.list();
        return fileNames.length;
    }
    else
    {
        return 0;
    }
}

@Override
public boolean isLeaf(Object node) {
    return ((File)node).isFile();
}

@Override
public void valueForPathChanged(TreePath path, Object newValue) {

}

@Override
public int getIndexOfChild(Object parent, Object child) {
    File pathName = (File) parent;
    File childName = (File) child;
    if(pathName.isDirectory())
    {
        String[] fileNames = pathName.list();
        for (int i = 0; i < fileNames.length; i++) {
            if(pathName.compareTo(childName) == 0)
            {
                return i;
            }
        }
    }
    return -1;
}

@Override
public void addTreeModelListener(TreeModelListener l) {

}

@Override
public void removeTreeModelListener(TreeModelListener l) {

}

}

I hope somebody can help me out, or just help me with ideas how to solve this problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:49:19+00:00Added an answer on June 14, 2026 at 7:49 pm

    Ok just to close this topic in case if someone find this.
    Its really long ago i worked on this but this is how we managed it:

    For the treeModel we made our custom nodes. Instead of sending a JTreeModel object trough a socket connection we only send the data that must be shown in the tree.
    After the client received the data from the server we iterated trough all the data and checked if the node is a parent or child.
    This can be done basically with the overrided TreeModel class code snipper above in my Question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a server/client application using sockets in C# for .NET 3.5. I'm
I have a basic client/server application written in Java which uses plain Sockets for
Background: I have written a java swing based client server application. The server is
I have written a small client server socket application. It is a proof of
I have a client/server application written in delphiXe2 using Indy TIdTCPServer and TIdTCPClient that
I have a Client/Server application written Delphi. Essentially all the application is doing is
I have a rather large client-server network application, written in Python. I'm using select.poll
I have a client-server application written in Java using CORBA for the communication. The
I have written client-server application in C. I run the server in linux. I
i have written a following hbase client class for remote server: System.out.println(Hbase Demo Application

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.