i trying put elements on listview , treeview javafx, both controls wont refresh theyre content. using obvservable list control items , every time delete 1 item, listview or treeview removes datasource. view not updating. still seeing items. difference is, removed item can not selected more. example link 2 shows collaped item list. image 1 shows items before collaped. items collapsed old entry still visible. know solution problem. thank helping me
link 1: treeview not collapsed link 2: treeview collapsed not updating old view
this custom cell factory use display listview:
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; }
your cell factory's updateitem(...)
needs handle case cell empty. scenario when item item removed (or becomes empty because node in treeview
collapsed) , cell showed item reused 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 code. } } } return cell ; }