Javafx listview and treeview controls not repainted correctly

I am trying to put items in listview and treeview using javafx, but both controls won't update theyre content. I am using an obvservable list to manage items and every time I remove one item the listview or treeview removes it from the datasource. but the view is not updated. I can still see all the items. The only difference is that the deleted item can no longer be selected. for example link 2 shows a list of collapsed items. Figure 1 shows the elements before smoothing them. the items are discarded, but the old entry is still visible. does anyone know a solution to this problem. thanks everyone for helping me

link 1: treeview does not dump link 2 : treeview is collapsed but does not update the old view

this is a custom cell factory I am using to display the list:

public ListCell<T> call(final ListView<T> param) {
        ListCell<T> cell = new ListCell<T>(){
            @Override
            protected void updateItem(final T persistentObject, final boolean empty) {
                super.updateItem(persistentObject, empty);
                if(persistentObject instanceof POProcessStep){
                    POProcessStep poProcessStep = (POProcessStep) persistentObject;
                    if (persistentObject != null) {
                        super.setText(poProcessStep.getId() + " - " + poProcessStep.getTitle());
                    }
                }else if(persistentObject instanceof POProcess){
                    POProcess poProcess = (POProcess) persistentObject; 
                    if (persistentObject != null) {
                        super.setText(poProcess.getId() + " - " + poProcess.getTitle());
                    }
                }else if(persistentObject instanceof POCategory){
                    POCategory poCategory = (POCategory) persistentObject;
                    if(persistentObject != null){
                        super.setText(poCategory.getId() + " - " + poCategory.getTitle());
                    }
                }else if(persistentObject instanceof String){
                    if(persistentObject != null){
                        super.setText(String.valueOf(persistentObject));
                    }
                }
                super.setGraphic(null);
            }
        };
        return cell;
    }

      

+3


source to share


1 answer


Your factory cell updateItem(...)

should handle the case when the cell is empty. This will be exactly the scenario where the element is removed (or becomes empty since node in has TreeView

been collapsed) and the cell that previously showed the element is reused as an empty cell:



public ListCell<T> call(final ListView<T> param) {
    ListCell<T> cell = new ListCell<T>(){
        @Override
        protected void updateItem(final T persistentObject, final boolean empty) {
            super.updateItem(persistentObject, empty);
            if (empty) {
                setText(null);
                setGraphic(null);
            } else {
                // ... rest of your code.
            }
       }
    }
    return cell ;
}

      

+13


source







All Articles