1

I have a Client_manager named CM that return an arrayList.

public class Client_Manager {
private static Client_Manager self = null;
private ArrayList<Client_Thread> clientList;
public Client_Manager() {
    self = this;
    this.clientList = new ArrayList<>();
}



public static Client_Manager getInstance()
{
    if(self == null)
        self = new Client_Manager();

    return self;
}

public void addClientThread(Client_Thread client)
{
    this.clientList.add(client);
}

public Client getClientAt(int index)
{
    return this.clientList.get(index).getOwner();
}

public void removeClient(int index)
{
    this.clientList.remove(index);
}

public ArrayList<Client> getClientList() {
    ArrayList<Client> ar = new ArrayList<>();
    for(int count1 = 0; count1 < clientList.size(); count1++)
    {
        ar.add(clientList.get(count1).getOwner());
    }

    return ar;
}
}

and Jlist named 'showClient'. What i am trying to do is get the arraylist from CM.(CM.getClientList) to show up in the jlist showClient. Furthurmore, i want it update the changes every time CM get new clients. How should i begin? first time assignment with swing.

Need someone to point me to the right direction either documents or an examples. ...

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Ton. Lia
  • 13
  • 5

1 Answers1

2

Let ClientManager contain a ListModel<Client> that is updated with each added Client. Any listening JList having that model will update itself in response. Complete examples may be found here and here. The exact details depend on context, but the ListModel<Client> must be updated on the event dispatch thread. If receiving clients causes unpredictable latency, use a worker thread.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • i was told that it is not suppose to have any graphical component in clientmanager class. – Ton. Lia May 15 '16 at 04:29
  • Please edit your question to an [mcve] that reflects this requirement. `ClientManager` needn't contain any view component; it just needs to update the view's model. – trashgod May 15 '16 at 05:10