listview - make list view show what I want JavaFX -


i have created class , added observable list, have list view set item observable list.

problem when add object class observable list, list view shows address on memory package.testclass@574f5892, how can make list view show text stored in each object , image instead of memory address?

thanks

a quick hack define tostring method in testclass returning text want display. isn't robust solution, because in general might want tostring() method return different text want displayed in gui environment.

the "proper" way set cellfactory on list view. along lines of

listview.setcellfactory(lv -> new listcell<testclass>() {     @override     public void updateitem(testclass item, boolean empty) {         super.updateitem(item, empty);         if (empty) {             settext(null);         } else {             string text = ... ; // text item             settext(text);         }     } }); 

to include image, can do

listview.setcellfactory(lv -> new listcell<testclass>() {      private final imageview imageview = new imageview();     @override     public void updateitem(testclass item, boolean empty) {         super.updateitem(item, empty);         if (empty) {             settext(null);             setgraphic(null);         } else {             string text = ... ; // text item             settext(text);             image image = ... ; // image item             imageview.setimage(image);             setgraphic(imageview);         }     } }); 

Popular posts from this blog