jlist - Access custom object in ListCellRenderer JAVA -
i have custom object includes specific image url & name. , have listcellrenderer class show image , text. want ask how can access custom object's image url in listcellrenderer class ? listcellrenderer class:
class customcellrenderer extends jlabel implements listcellrenderer { private imageicon image; public customcellrenderer() { setopaque(true); // want use list item's image url image here image = new imageicon( "img/mark.png" ); } public component getlistcellrenderercomponent( jlist list, object value, int index, boolean isselected, boolean cellhasfocus ) { // display text item settext(value.tostring()); // set correct image seticon( image ); // draw correct colors , font // if( isselected ) // { // // set color , font selected item // setbackground( color.red ); // setforeground( color.white ); // } // else // { // // set color , font unselected item // setbackground( color.white ); // setforeground( color.black ); // } return this; } }
Comments
Post a Comment