JAVA - How to change JTable row color after clicking on it? -


i 'm java beginner. create application jtable populated database. in database have 'news'. in jtable display titles of 'news' , when user click on row, display popup right contents of news. want colorize cell 'read' when user clicked on it.

i use own tablemodel.

i hope i'm clear...

if need put code, tell me please...

public class jtabletest extends jframe {      private jtable      table;     private int         col;     private int         rowz;       /**      * create frame.      */     public jtabletest() {         initcomponents();     }      private void initcomponents() {         /** other components */          table = new jtable();//create table         table.setdefaultrenderer(object.class, new custommodel());         table.addmouselistener(new customlistener());     }      public class customlistener extends mouseadapter {         @override         public void mouseclicked(mouseevent arg0) {             super.mouseclicked(arg0);             //get clicked cell's row , column             rowz = table.getselectedrow();             col = table.getselectedcolumn();              // repaints jtable             table.repaint();         }     }      public class custommodel extends defaulttablecellrenderer {           private static final long   serialversionuid    = 1l;          @override         public component gettablecellrenderercomponent(jtable table, object value, boolean isselected, boolean hasfocus, int row, int column) {             jlabel label = (jlabel) super.gettablecellrenderercomponent(table, value, isselected, hasfocus, row, column);             color c = color.white;//define color want             if (isselected && row == rowz & column == col)                 c = color.green;             label.setbackground(c);             return label;         }     }  } 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -