swing - Java JTable TableCellRenderer With ImageIcon Column -
i have table custom table model has 2 columns. column 0 imageicon class, , column 1 string class.
public class<?> getcolumnclass(int col) { if (col == 0) { return imageicon.class; } else { return string.class; } }
when define new tablecellrenderer class added columns can style cells, overwrites imageicon class , sets string.
public class customtablecellrenderer extends defaulttablecellrenderer { public component gettablecellrenderercomponent (jtable table, object obj, boolean isselected, boolean hasfocus, int row, int column) { component cell = super.gettablecellrenderercomponent(table, obj, isselected, hasfocus, row, column); if(isselected) cell.setbackground(color.blue); return cell; } }
any ideas on how fix this?
my mistake, sort of hidden:
when define new tablecellrenderer class added columns can style cells, overwrites imageicon class , sets string.
so problem that, when define tablecellrenderer class style table, imageicon columns in table turn strings "file:..." instead of actual icon.
there no need create custom renderer. jtable allready supports default renderer columns containing icon. need override getcolumnclass() method, appear doing.
Comments
Post a Comment