CoupFlu
CoupFlu

Reputation: 321

implements ListModel, need to update JList on Change

I have a custom collection which implements ListModel. When this collection changes, i need to notify the JList. Typically you'd fireListDataChanged, but this is not a method implemented by ListModel.

How should I go about modifying my code to automatically update the JList?

JList here:

this.selectedInterfacesJList.setModel(new TufinInterfaceCollection());

Collection here:

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);
    }    
}

Upvotes: 0

Views: 154

Answers (0)

Related Questions