I have a JList with a custom DefaultListModel. The JList is inside a JScrollPane that is inside a JTabbedPane. When I update the model by adding or removing elements I see no changes on the page even though the model has properly changed.
I tried to revalidate() and repaint() everything and it didn't change.
Now comes the funny thing. If I print every thing in model with a for (int i = 0; i < model.size(); i++) model.get(i) it only shows the modified list. BUT if I go through the list inside my custom model by putting it public, nothing has been changed.
The List I can view updates only if I create and set a new model with another List that I filled manually.
TLDR;
After modifying list in custom DefaultListModel with addElement and removeElement how can this shows the modified list :
for (int i = 0; i < model.size(); i++) {
System.out.println(model.get(i));
}
And this shows the original list and the view is therefore not being updated
for (Object object : model.list) {
System.out.println(object);
}
My DefaultListModel class
public class ObjectListModel extends DefaultListModel
{
final List<Object> list;
public ObjectListModel(List<Object> list) {
this.list = list;
}
@Override
public int getSize() {
return list.size();
}
@Override
public Object getElementAt(int index) {
return list.get(index);
}
}