JList 更新对象返回 arraylist

JList updating with Object returning arraylist

我有一个 Client_manager 名为 CM,return 一个 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;
}
}

和 Jlist 命名为 'showClient'。我想要做的是从 CM.(CM.getClientList) 获取数组列表以显示在 jlist showClient 中。此外,我希望它在每次 CM 获得新客户时更新更改。我应该如何开始?第一次与秋千分配。

需要有人为我指明正确的方向,无论是文档还是示例。 ...

ClientManager包含一个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