okay, here is the problem, I am writing a simple chat program. a client has a JFrame
called the ChatList
class that contains a JList
which shows online users. The list is refreshed with new status of users every 2 seconds using this method:
public void refresh(ArrayList<String> onlineUsers) {
System.out.println(onlineUsers);
DefaultListModel listModel2 = new DefaultListModel();
for (int i = 0; i < onlineUsers.size(); i++) {
if (!onlineUsers.get(i).equals(client.userName))
listModel2.addElement(onlineUsers.get(i));
}
if (!listModel2.equals(listModel)) {
listModel=listModel2;
listbox.setListData(listModel.toArray());
listbox.validate();
}
topPanel.add(listbox, BorderLayout.CENTER);
this.setVisible(true);
}
if the user chooses a client to chat to, another JFrame
opens. The problem is that this JFrame
wont hold the focus and the focus alternatively swings between the ChatList
and the ChatWindow
, which causes the user not to have enough time to even write a simple "Hello". so now I have 2 questions:
- is it because of updating my jlist?
- is there a way to stop this and make the
ChatList
only get the focus when i click on it and not by updating it?