小石頭
          Excellence in any department can be attained only by the labor of a lifetime; it is not to be purchased at a lesser price.
          posts - 91,comments - 22,trackbacks - 0
            public   class   MyTableRenderer   extends   DefaultTableCellRenderer   {  
                    public   Component   getTableCellRendererComponent(JTable   table,  
                                  Object   value,   boolean   isSelected,boolean   cellHasFocus,  
                                  int   row,int   col)   {  
                   
                              switch(row){  
                              case   0:  
                              case   1:  
                                        this.setBackground(Color.red);  
                                        break;  
                              case   2:  
                              case   3:  
                                        this.setBackground(Color.blue);  
                                        break;  
                              }  
                  if(isSelected){  
                        //這里寫如果選中后你想表現出來的效果;        
                  }  
                  if(isFocus){  
                        //這里寫如果獲得焦點后你想表現出來的效果;        
             
                  }  
                  this.setText((String)object);  
                  return   this;  
                  }  
            }  
             
             
            然后為你的table添加一個上面類的實例作為繪制器.  
            比如  
            JTable   table   =   new   JTable(data);  
            table.setDefaultRenderer(new   String().getClass(),new   MyTableRenderer());  
             
            試試看.  
          posted on 2007-05-23 22:57 小石頭 閱讀(525) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 盐池县| 左贡县| 焉耆| 增城市| 鲁甸县| 江城| 安徽省| 沙河市| 淳安县| 英吉沙县| 无为县| 绥棱县| 徐汇区| 武清区| 南陵县| 临西县| 屏边| 浦北县| 巴中市| 德化县| 大同县| 昭通市| 师宗县| 德昌县| 北宁市| 图片| 常德市| 体育| 德庆县| 怀仁县| 都昌县| 思南县| 丰镇市| 京山县| 丽江市| 宜君县| 麻栗坡县| 秦皇岛市| 松江区| 巴彦淖尔市| 潮州市|