Java Swing - Unable access jTable from different function -


i've created jtable per below:

public void reftable(string jobno) {         report rp = new report();         final string nojob = jobno;             map<integer, string> jmap = rp.getreportinfo(jobno);         map<integer, string> sortedmap = new treemap<integer, string>(jmap);             string[] row = new string[sortedmap.size()];         integer[] no = new integer[sortedmap.size()];         string[] stat = new string[sortedmap.size()];         boolean[] dev = new boolean[sortedmap.size()];         string[] remark = new string[sortedmap.size()];         boolean[] rem = new boolean[sortedmap.size()];         string userremark[] = new string[sortedmap.size()];         tabsize = sortedmap.size();         int = 0;          (integer key : sortedmap.keyset()) {             no[i] = key;              string []val = sortedmap.get(key).split("###");             if (val[0].trim().equals("dev")) {                 stat[i] = "fail";             } else {                 stat[i] = val[0].trim();             }               string []strremark = val[1].split("no");              //tempremark = strremark[0];              remarkdropdownlist.devtempvalue =val[1].split("no");              row[i] = strremark[0].trim().replaceall("yes", "");//             //row[i] = val[1].trim();             if(strremark.length<2)             dev[i] = false;             else             dev[i] = true;                 remark[i] = "";             if(strremark.length<2)             userremark[i] = "";             else                 if(remarkdropdownlist.userothersreamrk!=null)             userremark[i] = remarkdropdownlist.userselecteditem;                else               userremark[i] = strremark[1];                   //remark[i] = false;            /*if(userremark1[i]!=null)             userremark[i] = userremark1[i];//remarkdropdownlist.userothersreamrk;             else             userremark[i] ="";   use when drop down*/             rem[i] = false;             i++;         }          defaulttablemodel model = new defaulttablemodel();         model.firetabledatachanged();         jtable1.setmodel(model);             model.addcolumn("no:", no);         model.addcolumn("status:", stat);         model.addcolumn("details:", row);         model.addcolumn("non-deviation", dev);         model.addcolumn("remarks", remark);         model.addcolumn("remove", rem);         model.addcolumn("ur", testremark);          tablecolumn col1 = jtable1.getcolumnmodel().getcolumn(0);         col1.setpreferredwidth(30);          tablecolumn col2 = jtable1.getcolumnmodel().getcolumn(1);         col2.setpreferredwidth(30);          tablecolumn col3 = jtable1.getcolumnmodel().getcolumn(2);         textrenderer renderer = new textrenderer();         col3.setcellrenderer(renderer);         col3.setpreferredwidth(350);          cellrenderer cellrender = new cellrenderer();         tablecolumn col4 = jtable1.getcolumnmodel().getcolumn(3);         col4.setcelleditor(jtable1.getdefaulteditor(boolean.class));         col4.setcellrenderer(cellrender);         col4.setpreferredwidth(50);          tablebutton buttoneditor = new tablebutton("button");         buttoneditor.addtablebuttonlistener(new tablebuttonlistener() {             //@override             public void tablebuttonclicked(int row, int col) {                 remarkdropdownlist rmk = new remarkdropdownlist(nojob, row);             }         });         tablecolumn col5 = jtable1.getcolumnmodel().getcolumn(4);         col5.setcellrenderer(buttoneditor);         col5.setcelleditor(buttoneditor);           tablecolumn col6 = jtable1.getcolumnmodel().getcolumn(5);         col6.setcelleditor(jtable1.getdefaulteditor(boolean.class));         col6.setcellrenderer(jtable1.getdefaultrenderer(boolean.class));         col6.setpreferredwidth(50);         jtable1.setshowgrid(true);         jtable1.setgridcolor(color.black);         jtable1.setautocreaterowsorter(true);        } 

i tried clear jtable different function in same class this.

public void clear() { jtable1.setmodel(new defaulttablemodel()); } 

the jtable not cleared per expected. when try move jtable1.setmodel(new defaulttablemodel()); main function reftable() jtable cleared. add on, not able clear jtable, looks don't have access jtable @ all.please advice.

this clear table you. must first create new default table model, set it, , set row count 0.

public void clear(){   defaulttablemodel tm=new defaulttablemodel();  jtable1.setmodel(tm);  tm.setrowcount(0); } 

hope helped.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -