I have a program designed as an MVC-pattern, where my model extends AbstractListModel. When i add a new user to my model is use following code:
public synchronized void addUser(User u) {
if (!users.contains(u)) {
users.add(u);
Collections.sort(users);
//fire
fireIntervalAdded(ListDataEvent.INTERVAL_ADDED, getSize(), getSize());
}
}
And it works fine, sometimes. But the JList isnt allways updating. Sometimes it works, and some times not... Any clue? And of course, the users im adding is always added to the model, but there is something wrong with the fireIntervalAdded/JList
EDIT: if i change the code to following:
public void addUser(final User u) {
if (!users.contains(u)) {
users.add(u);
Collections.sort(users);
}
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
fireIntervalAdded(this, getSize(), getSize());
}
});
}
it works perfect. So the problem was that it wasnt the EDT that did the fire thing. Thx! Now i will rewrite it so it will be nice code aswell.