Add listener to ArrayList

前端 未结 8 1315
再見小時候
再見小時候 2020-12-09 17:14

I have an ArrayList which I add some Objects to it dynamically, and I have a JButton. The ArrayList is empty when running my program and the JButton is set to setEnabled(fal

8条回答
  •  借酒劲吻你
    2020-12-09 17:37

    Javafx (part of JRE 8) provides an observable list implementation. This code works for me:

    ObservableList lstAnno1 = FXCollections.observableList(new ArrayList());
    
    lstAnno1.addListener((ListChangeListener.Change c) -> {
       c.next();
       updateAnnotation((List) c.getAddedSubList(), xyPlot);
    });
    
    ...
    lstAnno1.add(new MyAnno(lTs, dValue, strType));
    ...
    
    public void updateAnnotation(List lstMyAnno, XYPlot xyPlot) {
       lstMyAnno.forEach(d -> {
       ...
       });
    }
    

提交回复
热议问题