java - Change Color Of JTable Rows -


i have 2 jtables tblorderinfo , tbldetailinfo want color tblorderinfo rows on basis of tbldetailinfo rows, have done lots of research , found rob camick's article , many other articles works coloring based on static values checking , not work case dynamic filtering of jtable.

i tried function using rob's approach not works.

    private component createcoloring(defaulttablemodel model)     {     tblorderinfo = new jtable( model )     {     public component preparerenderer(tablecellrenderer renderer, int row, int column)     {     component c = super.preparerenderer(renderer, row, column);      //  color row based on cell value      if (!isrowselected(row))     {         c.setbackground(getbackground());         int modelrow = convertrowindextomodel(row);         string type = (string)getmodel().getvalueat(modelrow, 0);       object orderid="";     object design="";     object sno="";                           for(int r=0;r< tbldetailinfo.getrowcount();r++){     orderid= tbldetailinfo.getvalueat(r,  util.getcolumnindex( tbldetailinfo, "orderid"));     design= tbldetailinfo.getvalueat(r,  util.getcolumnindex( tbldetailinfo, "design"));     sno= tbldetailinfo.getvalueat(r,  util.getcolumnindex( tbldetailinfo, "sno"));      for(int o=0;o< tblorderinfo.getrowcount();o++){     if(( tblorderinfo.getvalueat(o,  util.getcolumnindex( tblorderinfo, "orderid")).equals(orderid))     && ( tblorderinfo.getvalueat(o,  util.getcolumnindex( tblorderinfo, "design")).equals(design))     && ( tblorderinfo.getvalueat(o,  util.getcolumnindex(tblorderinfo, "sno")).equals(sno))      ){      c.setforeground(color.red);         }     }       }     }      return c;     }     };      tblorderinfo.setpreferredscrollableviewportsize(tblorderinfo.getpreferredsize());     tblorderinfo.changeselection(0, 0, false, false);     tblorderinfo.setautocreaterowsorter(true);     return tblorderinfo;     } 

the calling code below

 defaulttablemodel dtm =(defaulttablemodel)    tblorderinfo.getmodel();   jscrollpane2.remove(tblorderinfo);    jscrollpane2.add(createcoloring(dtm));  

the preparerenderer() method called every cell basic code structure wrong. loop throw row in 1 table , rows in second table. row colored if match found anywhere , same every row in table.

i want color tblorderinfo rows on basis of tbldetailinfo rows,

i think basic pseudo code should be:

foreach row in detail table      if ((detail.orderid.equals(order.orderid)     , (detail.design.equals(order.design)     , (detail.sno.equals(order.sno))     {         c.setforeground( color.red);         break;         } 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -