I have a ListView in JavaFX and when I'm deleting a item there will show up more items in the ListView but not in the list.
Declaration of ObservableList and Extractor
Callback<ElectricDeviceType, Observable[]> deviceTypeExtractor = new Callback<ElectricDeviceType, Observable[]>() {
@Override
public Observable[] call(ElectricDeviceType t) {
return new Observable[] { t.maxValue, t.name, t.getDevices() };
}
};
ObservableList<ElectricDeviceType> deviceTypes = FXCollections
.observableArrayList(deviceTypeExtractor);
Here I'm setting the Devices to the ListView
public void setElectricDevices(ElectricDeviceType... list) {
deviceTypes.addAll(list);
deviceTypeList.setItems(deviceTypes);
deviceTypeList
.setCellFactory(new Callback<ListView<ElectricDeviceType>, javafx.scene.control.ListCell<ElectricDeviceType>>() {
@Override
public ListCell<ElectricDeviceType> call(
ListView<ElectricDeviceType> listView) {
return new ElectricDeviceTypeListViewCell(_this,
simulation);
}
});
}
Class ElectricDeviceTypeListViewCell
public class ElectricDeviceTypeListViewCell extends ListCell<ElectricDeviceType> {
private MainWindowController controller;
private Simulation simulation;
public ElectricDeviceTypeListViewCell(MainWindowController c, Simulation s) {
controller = c;
simulation = s;
}
@Override
public void updateItem(ElectricDeviceType t, boolean empty) {
super.updateItem(t, empty);
if (t != null) {
ElectricDeviceTypeController data = new ElectricDeviceTypeController(controller, simulation);
data.setInfo(t);
setGraphic(data.getBox());
}
}
}
When I delete one item from my observable list, my listview shows 5 items instead of 2. But my observable only has 2 items inside. If I delete all of my items then i the duplicates are deleted too.
Could you please help me with that?