java - Update Table GUI that extends custom AbstractTableModel -


i created java gui displays table using following syntax:

table = new jtable(new mytablemodel(columnnames,                                     updatetable(cmbadversary.getselecteditem().tostring(),                                                 cmbdatatype.getselecteditem().tostring()))); 

where columnnames vector of strings cmbadversary , smbdatatype selection od combo boxes.

and updatetable method returns vector of vectors depending on combo box selection follows:

static vector updatetable(string filterval1 , string filterval2)  { try {     myvector = tssc.testseverityfunctionservice(filterval1,filterval2); } catch (exception e) { e.printstacktrace();} return myvector; } 

this how custom class mytablemodel extends abstracttablemodel looks like:

class mytablemodel extends abstracttablemodel  {     vector columnnames = new vector();     vector fdb = new vector();      public mytablemodel(vector cname,vector rname){         this.columnnames = cname;         this.fdb = rname;}     public int getcolumncount() { // number of columns in model.         return columnnames.size();     }     public int getrowcount() { // number of rows in model.         return fdb.size();     }     @override     public string getcolumnname(int col) {         return columnnames.get(col).tostring();     }     public object getvalueat(int row, int col) {         vector v = (vector) this.fdb.get(row);         return v.get(col);     }     @override     public class getcolumnclass(int c) {         vector v = (vector) fdb.get(0);         return v.get(c).getclass();}      public boolean iscelleditable(int row, int col)     {       return true;    }      public void setvalueat(vector value, int row, int col)      {         for(int i=0;i<value.size();i++)         { for(int j=0;j<columnnames.size();j++) {                     fdb.setelementat(value.get(j),j);   }         }         firetablecellupdated(row, col);     }  } 

the problem when run code, table gui show me initial values fails update when change selection in 2 comboboxes , click selection button. selection button, btw, calls method implements action listener.

please me out. no pro in java, willing learn. if have followup qs., i'll happy provide details.

your solution seems overly complicated. if understand basics, user chooses value combo box, based on selection data loaded table.

there no need create custom table model this.

a tablemodel contains data. if want change data, 1 way create new tablemodel. add actionlistener combo box. when item selected retrive data , load data vector or array. using data can create new tablemodel , update jtable in 2 lines of code:

defaulttablemodel model = new defaulttablemodel(...); table.setmodel( model ); 

if need customize model override getcolumnclass() or iscelleditable() methods, should extend defaulttablemodel. don't see need implement whole model.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -