java - Garbage value in jtable after adding row dynamically -
i have jtable
has few columns.in have jcombobox
. @ program start want them empty.i have 1 jbutton
on click action of button have code add row dynamically in table.
but after adding row garbage value in cell having jcombobox
. shown in below figure :
and here code :
code add jcombobox in table
// create columns names string columnnames[] = { "item", "sun item", "required quantity","price","gross amount" }; // create data final string datavalues[][] = { { "", "", "","","", }, }; tablemodel = new defaulttablemodel(datavalues, columnnames); // create new table instance table = new jtable( tablemodel ); updateitemcombo(); tablecolumn itemcolumn = table.getcolumnmodel().getcolumn(0); itemcolumn.setcelleditor(new defaultcelleditor(comboitem)); public void updateitemcombo(){ vector<string> s = new vector<string>(); try{ setconnectin(); string str = "select * itemtable"; stmt = conn.createstatement(); rs = stmt.executequery(str); while(rs.next()) { string nm = rs.getstring("item_name"); s.add(nm); } conn.close(); }catch(exception e2){ e2.printstacktrace(); } defaultcomboboxmodel<string> modeldata = new defaultcomboboxmodel<string>(s); comboitem.setmodel(modeldata); }
code add row dynamically on button click :
btnaddorder.addactionlistener(new actionlistener() { public void actionperformed(actionevent arg0) { tablemodel.addrow(datavalues); tablemodel.firetabledatachanged(); } });
what should remove garbage value table? please help
the addrow(...) method takes 1-dimensional array parameter. attempting add 2-dimensional array.
also, not use:
tablemodel.firetabledatachanged();
it job of tablemodel invoke appropriate firexxx() method, way in case firetablerowsinserted(...)
.
Comments
Post a Comment