java - Trying to refresh JTable from third party using abstractTableModel -
when using button event success display update table in gui window, the problem when want refresh data update() method(=from third party). read realize need use abstracttablemodel ,so create mytablemodel class , still without success, due worng implement method. try alot appreciate suggest or solution please :) ![enter image description here][1] scrn shot before , after press button, want same result calling update
public void update() { try { int col = 0, row = 0; vector<object> data = new vector<object>(); vector<object> colname = new vector<object>(); system.out.println("refresh list ..."); system.out.println("update have done!"); query = "select * data"; pst = connection.preparestatement(query); rs = pst.executequery(); resultsetmetadata md = rs.getmetadata(); col = md.getcolumncount(); (int = 1; <= col; i++) { colname.addelement(md.getcolumnname(i)); system.out.println(colname.get(i - 1)); } int tmp = 0; while (rs.next()) { (int = 1; <= col; i++) { data.addelement(rs.getstring(i)); system.out.println(data.get(tmp)); tmp++; } row = tmp; } mytablemodel mtm=new mytablemodel(data, colname); pst.close(); rs.close(); } catch (exception e) { e.printstacktrace(); } }
my working button event more understanding`
btnloadtable.addactionlistener(new actionlistener() { public void actionperformed(actionevent arg0) { system.out.println("hey click me man!!!!!!!!!!!"); try { system.out.println("refresh list ..."); system.out.println("update have done!"); string query = "select id,candidatename,company,link data"; pst = connection.preparestatement(query); resultset rs = pst.executequery(); table.setmodel(dbutils.resultsettotablemodel(rs)); pst.close(); rs.close(); } catch (exception e) { e.printstacktrace(); } } });`
and last try implement class mytablemodel class
class mytablemodel extends abstracttablemodel { vector<object> colaname= new vector<object>(); vector<object> celldata = new vector<object>(); //constructor table model public mytablemodel(vector<object> data,vector<object> colname ) { super(); this.colaname=colname; this.celldata=data; } //------------7 public void insertdata(vector vector) { int length=getrowcount(); (int = 0; < length; i++) { celldata.addelement(vector.get(i)); } firetabledatachanged(); } //------------1 @override public string getcolumnname(int col) { return colaname.get(col).tostring(); } //------------2 @override public int getcolumncount() { return colaname.size(); } //------------3 @override public int getrowcount() { return celldata.size(); } public void setvalueat(vector value, int row, int col) { celldata= value; firetablecellupdated(row, col); } //------------4 @override public object[][] getvalueat(int row, int col) { int row1=getrowcount(); int col1=getcolumncount(); object[][] tabledata = new object[row1][col]; (int = 0 ; < col1 ; i++) { (int j = 0 ; j < row1 ; j++) { tabledata[i][j] = celldata; system.out.println("////////////////////////////"); system.out.println(tabledata[i][j]); } } return (object[][]) tabledata[row1][col1]; } //------------5 @override public class getcolumnclass(int c) { c=getcolumncount(); return getvalueat(0, c).getclass(); } }`
Comments
Post a Comment