java - Jtable does not refresh after inserting a new data -
here iam trying search prodcuts jtable.but problem is,the new search results getting added under previous search results , not updating jtable used firetabledatachanged() method.
here code
@override public void actionperformed(actionevent e) { system.out.println("im in createiban values: " +combobox.getselecteditem()+ " , " + textfield.gettext()); if(combobox.getselecteditem().tostring().equals("serial no")) { system.out.println("0"); string cmb=textfield.gettext().tostring(); try{ con= (connection) connect.connectdb(); string sql="select * stocks serial=?"; pst = (preparedstatement) con.preparestatement(sql); pst.setstring(1, cmb); rs=pst.executequery(); model = (defaulttablemodel) jt.getmodel(); model.firetabledatachanged(); **//here used method** while(rs.next()) { dt = rs.getstring("date"); mdt = rs.getstring("mdate"); srn = rs.getstring("serial"); mod = rs.getstring("model"); cap = rs.getstring("capacity"); inv = rs.getstring("invoice"); amt = rs.getstring("amount"); int i; for(i=0; i<model.getrowcount(); i++){ {} } jt.repaint(); model.firetabledatachanged(); **//here used method** model.addrow(new object[]{i+1,mod,cap,dt,mdt,srn,inv,amt}); joptionpane.showmessagedialog(this,"succesfully stored","user",joptionpane.information_message); } } catch (classnotfoundexception ex) { logger.getlogger(viewstock.class.getname()).log(level.severe, null, ex); } catch(sqlexception ex){ system.out.print(ex); }
hai guys found solution that,it use full people seeking type of question's answer,so post code here
just make method called reset() inside
defaulttablemodel model; model = (defaulttablemodel) jtable1.getmodel(); void reset() { for(int i=model.getrowcount()-1; i>=0;i--) { model.removerow(i); } }
and call reset method anywhere want,it work fine simple codes,good luck
Comments
Post a Comment