java - Placing an image into a JavaFX 2 table -


i'm trying pretty simple. want place icon in column particular row in table. if it's folder, display folder icon. if it's file, display file icon.

does know how in javafx 2?

i've tried many things , seems should pretty simple or @ least example somewhere.

okay had huge dummy moment. turns out had image url path wrong.

i did find site provides great example adding elements table. helped me understand everything.

now if 4 different ways tried before would've worked, don't know because image url path wrong. anyway here link , code snippet.

bottom line need have cellvaluefactory , cellfactory. attempting use either or. updateitem template method in tablecell relies on value dervied cellvaluefactory.

http://blog.ngopal.com.np/2011/10/01/tableview-cell-modifiy-in-javafx/

       tablecolumn albumart = new tablecolumn("album art");     albumart.setcellvaluefactory(new propertyvaluefactory("album"));     albumart.setprefwidth(200);        // setting cell factory album art                  albumart.setcellfactory(new callback<tablecolumn<music,album>,tablecell<music,album>>(){             @override     public tablecell<music, album> call(tablecolumn<music, album> param) {                         tablecell<music, album> cell = new tablecell<music, album>(){             @override             public void updateitem(album item, boolean empty) {                                         if(item!=null){                                                 hbox box= new hbox();                     box.setspacing(10) ;                     vbox vbox = new vbox();                     vbox.getchildren().add(new label(item.getartist()));                     vbox.getchildren().add(new label(item.getalbum()));                       imageview imageview = new imageview();                     imageview.setfitheight(50);                     imageview.setfitwidth(50);                     imageview.setimage(new image(musictable.class.getresource("img").tostring()+"/"+item.getfilename()));                       box.getchildren().addall(imageview,vbox);                      //setting graphics component cell                     setgraphic(box);                 }             }         };         system.out.println(cell.getindex());                        return cell;     }  }); 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -