swing - text field in jTable something better than ActionPerformed(java.awt.event.ActionEvent evt)! -


hi guys hope well.. day have question again using text field in jtable edit column , use model.getvalueat(); column , model.setvalueat(); column after doing calculations fanaly when press enter key action replays not reply , not update changing have press again... code looks this:

private void txt_actionperformed(java.awt.event.actionevent evt){  try {         int viewrow = table.getselectedrow();         string id = (table.getmodel().getvalueat(viewrow, 1).tostring());          string sql1 = "select * mydb.mytable_1 id1='"+id1+"'";         dm.pst = dm.c.preparestatement(sql1);         dm.rs = dm.pst.executequery();         if (dm.rs.next()) {         float = dm.rs.getfloat("mycolumn_1");         float b = float.parsefloat(model.getvalueat(viewrow, model.getcolumncount()-10).tostring());         float c = float.parsefloat(model.getvalueat(viewrow, model.getcolumncount()-9).tostring());         string d = model.getvalueat(viewrow, model.getcolumncount()-8).tostring();          float e = 0;         switch (d) {             case "u":case "1":e = 0;break;             case "w":case "2":e = 7;break;             case "x":case "3":e = 10;break;             case "y":case "4":e = 14;break;             case "z":case "5":e = 20;break;             default:system.err.println("error..");break;         }         if(b>a){              joptionpane.showmessagedialog(null, "b bigger a..!!");         }else if(a>=b){            float val_1 = a-b           float val_2 = b * c;           float val_3 = b * (((e / 100) + 1) * c);         model.setvalueat(val_3, viewrow, model.getcolumncount()-6);          model.setvalueat(val_2, viewrow, model.getcolumncount()-7);          model.setvalueat(val_1, viewrow, model.getcolumncount()-11);          string id2 = (table.getmodel().getvalueat(viewrow, 0).tostring());         string upid = "update mydb.mytable_2 set mycolumn_2='" + b + "'where id2='" + id2 + "'";         dm.pst = dm.c.preparestatement(upid);         dm.pst.execute();         }     }      } catch (exception ex) {         joptionpane.showmessagedialog(null, ex);     } 

}

anything else better action performed? note: after edited code using jtextfield txt_ = new jtextfield(); editor column , using model = new defaulttablemodel() thank in advance

i using text field in jtable edit column , use model.getvalueat(); column , model.setvalueat(); column

don't use actionlistener.

your logic should defined in tablemodel

@override public void setvalueat(object value, int row, int column) {     super.setvalueat(...);      if (column == ?)         //  add logic here calculation , update other column value } 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -