我有一个实现ListModel
的自定义集合。当此集合发生变化时,我需要通知JList
。通常您需要fireListDataChanged
,但这不是ListModel
实施的方法。
我应该如何修改代码以自动更新JList
?
JList:
this.selectedInterfacesJList.setModel(new TufinInterfaceCollection());
此处收集:
public class TufinInterfaceCollection extends AbstractCollection<TufinInterface> implements ListModel<String> {
ArrayList<TufinInterface> list=new ArrayList();
private final ArrayList listeners=new ArrayList();
@Override
public boolean remove(Object o) {
return list.remove(o); //To change body of generated methods, choose Tools | Templates.
}
@Override
public boolean add(TufinInterface e) {
return list.add(e); //To change body of generated methods, choose Tools | Templates.
}
public TufinInterface get(int i){
return list.get(i);
}
@Override
public Iterator<TufinInterface> iterator() {
return list.iterator();
}
@Override
public int size() {
return list.size();
}
@Override
public int getSize() {
return size();
}
@Override
public String getElementAt(int i) {
return get(i).toString();
}
@Override
public void addListDataListener(ListDataListener ll) {
this.listeners.add(ll);
}
@Override
public void removeListDataListener(ListDataListener ll) {
this.listeners.remove(ll);
}
}