来自{{的Change类中的方法 next , getFrom , getTo , getRemoved ... 1}}接口被声明为抽象。以下摘录来自该界面。
javafx.collections.ListChangeListener
如果我有一个班级来观察可观察名单的变化
public interface ListChangeListener<E> {
public abstract static class Change<E>{
public abstract boolean next();
public abstract void reset();
public void Change(ObservableList<E> list){
this.list = list;
}
public abstract int getFrom();
//... some more methods
}
public void onChanged(Change<? extends E> c);
}
例如,如何实现import javafx.beans.Observable;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.util.Callback;
// A class to detect changes in an observable list
public class ChangeQuery {
static IntegerProperty E1;
static IntegerProperty E2;
public static void main(String[] args) {
Callback<IntegerProperty, Observable[]> extractor = (IntegerProperty p) -> {
System.out.println("Extracted :" + p);
return new Observable[] {p};
};
ObservableList<IntegerProperty> list = FXCollections.observableArrayList(extractor);
list.addListener(ChangeQuery::onChanged);
E1 = new SimpleIntegerProperty(11);
E2 = new SimpleIntegerProperty(22);
list.add(E1);
list.add(E2);
E1.set(111);
}
public static void onChanged(ListChangeListener.Change<? extends IntegerProperty> change) {
System.out.println("GetList: " + change.getList());
while (change.next()) {
System.out.println(
"index [" + change.getFrom() + "] to " + "[" + change.getTo() + "]" ); // change.getFrom() implementation
if (change.wasPermutated()) {
System.out.println("Permutated is true");
} else if (change.wasUpdated()) {
System.out.println("Update == true");
} else if (change.wasReplaced()) {
System.out.println("removed and added == true");
} else if (change.wasRemoved()){
System.out.println("removed");
} else if (change.wasAdded()) {
System.out.println("Added");
}
}
}
}
方法。我检查了javafx.collection包,但没有找到这样的实现或错过的东西。预先感谢您的帮助。