You never set the disable
property back to false
. You need to do this for empty cells. The following could happen to a Cell
:
- a item is added to the
Cell
and the cell is disabled
- the item is removed from the
Cell
, the Cell
becomes empty, but it remains disabled.
In general when a Cell
becomes empty, any changes done to the Cell
when an item was added should be undone.
Furthermore you should avoid recreating the TextField
s every time a new item is assigned to a Cell
.
listView.setCellFactory(column -> {
return new ListCell<File>() {
private final TextField textField = new TextField();
protected void updateItem(File item, boolean empty) {
super.updateItem(item, empty);
if (item == null || empty) {
setDisable(false);
setGraphic(null);
} else {
setDisable(true);
textField.setText(item.getName());
setGraphic(textField);
}
}
};
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…