B
B
BaLahmuT2021-11-28 18:44:54
Java
BaLahmuT, 2021-11-28 18:44:54

How to remove element from JList, Thread?

I create a chat, it is possible to connect and disconnect from the chat, when connected, the user is added to the list of online users, it is necessary that when disconnected, the user is removed from the list. When one of the users disconnects, the chat window closes but it remains in the list of the other user. Each new user starts a separate thread. How to remove it?

Disconnect method from the network, called when the button is pressed

public void disconnect() throws IOException
    {
        PWOUT.println(ClientGUI.UserName + " has disconnected");
        PWOUT.flush();
        SOCKET.close();
        
        DefaultListModel dlm = new DefaultListModel(); 
        dlm.clear(); //удаляем всех 
        ClientGUI.listOnline.setModel(dlm); //обновляем 
        
        JOptionPane.showMessageDialog(null,
                "You disconnected!",
                "User disconnect", JOptionPane.INFORMATION_MESSAGE);
        System.exit(0);
    }

61a3a433e16dd108074583.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question