I start programming in java and I have not been clear about the observable lists, I have seen examples where they relate them to an ArrayList but I do not understand what the end of that relationship is.
I start programming in java and I have not been clear about the observable lists, I have seen examples where they relate them to an ArrayList but I do not understand what the end of that relationship is.
The ObservableList
interface is a list interface of JavaFX , and use FXCollections
to equip a list with additional functionality.
import java.util.List;
import java.util.ArrayList;
import javafx.collections.ObservableList;
import javafx.collections.ListChangeListener;
import javafx.collections.FXCollections;
public class EjemploObservableList {
public static void main(String[] args) {
// Se insta una lista.
List<String> list = new ArrayList<String>();
// se agrega la observación usando FXCollections:
ObservableList<String> observableList = FXCollections.observableList(list);
observableList.addListener(new ListChangeListener() {
@Override
public void onChanged(ListChangeListener.Change change) {
System.out.println("Ocurrio un cambio! ");
}
});
// Se reportan cambios a observableList.
// Aquí se va imprimir la alerta
observableList.add("uno");
// cambios directas a la lista escapan la observación
// no se imprime ninguna alerta
list.add("dos");
System.out.println("Tamano: "+observableList.size());
}
}