My ultimate goal is to have a JList that updates its contents at runtime, and I found a solution that works with this post here on SO , however I am curious why my original idea did not.
At the moment, I have something like this setting, and it works:
DefaultListModel default = new DefaultListModel();
for(int i = 0; i < array.size() ; ++i){
test.addElement(array.get(i));
}
list.setModel(default);
Below was my original plan. I wanted the class that implemented the ListModel to be passed as an argument, hoping it would update the JList.
SomeClass test = new SomeClass();
list.setModel(test);
or
SomeClass test = new SomeClass();
list = new JList(test);
None of these works bother me. Can these last two methods work like this, the code is so much cleaner.
Thank.
source
share