ListView using custom cell factory doesn't update after items deleted

后端 未结 2 1570
南笙
南笙 2020-12-16 22:48

I\'m learning JavaFX and i wanted to create a cell factory which is working properly until i want to delete a row from my ListView:



        
2条回答
  •  -上瘾入骨i
    2020-12-16 23:19

    According to the Java doc of Cell updateItem method, there is slightly different recomended usage than the accepted one:

    protected void updateItem(T item, boolean empty) {
        super.updateItem(item, empty);
    
        if (empty || item == null) {
            setText(null);
            setGraphic(null);
        } else {
            setText(item.toString());
        }
    }
    

    The difference is in the usage of parameter empty. But the sollution from @Adam should work correctly in major cases too.

提交回复
热议问题