首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在JTable Java中更改行背景

在JTable Java中更改行背景
EN

Stack Overflow用户
提问于 2012-07-16 23:52:45
回答 4查看 5K关注 0票数 0

我的项目中有一个名为tasktable的表。它从数据库(oracle)中检索数据。如何更改具有单元格ex中的颜色的行的颜色。(i,8)当我点击刷新按钮时自动?

我曾多次尝试将该源代码放在特定的行上,但最终导致整个表格着色:

代码语言:javascript
复制
          int count;      
          count = tasktable.getRowCount();
         for (int i=0;i<count;i++)
            { 
                  rr = new Object ();
                   rr = tasktable.getModel().getValueAt(i,8);
                   if(rr.equals("GREEN"))
                   {
                 setBackground(Color.GREEN);
                   }
                    if(rr.equals("red"))
                   {
                       setBackground(Color.red);
                   }
                     if(rr.equals("BLUE"))
                   {
                      setBackground(Color.BLUE);
                   }
                      if(rr.equals("yellow"))
                   {
                     setBackground(Color.yellow);
                   }
                       if(rr.equals("pink"))
                   {
                     setBackground(Color.pink);
                   }
                       if(rr.equals(null))
                   {
                     setBackground(null);
                   }

如何才能帮助我解决这个问题?

EN

Stack Overflow用户

发布于 2012-07-17 00:00:13

代码语言:javascript
复制
 Component comp = super.getTableCellRendererComponent(
                  table,  value, isSelected, hasFocus, row, col);

 String s =  table.getModel().getValueAt(row, VALIDATION_COLUMN ).toString();
 comp.setForeground(Color.red);

http://www.java-forums.org/awt-swing/541-how-change-color-jtable-row-having-particular-value.html

票数 0
EN
查看全部 4 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11507913

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档