image - Display ImageIcons in jTables -
i have tried using code below display imageicons in jtable. when run program jtable displays empty space. p1.getpicture(); comes database. basically, there way modify below code such there way display imageicon in picture???
package tables; import javax.swing.imageicon; import javax.swing.jlabel; import javax.swing.table.abstracttablemodel; import java.util.arraylist; import entity.*; public class profiletable extends abstracttablemodel{ private static final long serialversionuid = 1l; private int rowcount, colcount; private string[] columnnames = {"clickid", "name", "gender", "website", "hobbies","favourite food", "dp"}; private object [][] data; private imageicon [][] icons; public profiletable(arraylist<profile> listofobjects) { rowcount = listofobjects.size(); colcount = columnnames.length; data = new object[rowcount][colcount]; //icons = new imageicon[rowcount][colcount]; (int = 0; < rowcount; i++) { /*copy arraylist element instance of myobject*/ profile p1 = (profile)(listofobjects.get(i)); p1.retrieveprofile(); data[i][0] = p1.getclickid(); data[i][1] = p1.getfirstname(); data[i][2] = p1.getgender(); data[i][3] = p1.getwebsite(); data[i][4] = p1.gethobbies(); data[i][5] = p1.getfood(); icons[i][6] = new imageicon(p1.getpicture()); } } @override public int getcolumncount() { // todo auto-generated method stub return colcount; } @override public int getrowcount() { // todo auto-generated method stub return rowcount; } @override public object getvalueat(int rowindex, int columnindex) { // todo auto-generated method stub return data[rowindex][columnindex]; } public string getcolumnname(int col) { return columnnames[col]; } }
override getcolumnclass
in tablemodel return imageicon 6th column:
@override public class getcolumnclass(int columnindex) { if(columnindex == 6){ return imageicon.class; } return object.class; }
Comments
Post a Comment