Answer the question
In order to leave comments, you need to log in
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);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question