我在我的项目中有一个名为tasktable
的表。它从数据库(oracle)中检索数据。如何更改单元格中具有颜色的行的颜色。 (我,8)自动当我点击刷新按钮?在JTable Java中更改行背景
我已经尝试了很多次穿上特定的一行源代码,但它结束了着色所有的表:
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);
}
如何能帮助我在这个问题?
你真的应该问之前做一些研究。这是一个非常常见和容易的事情。 http://stackoverflow.com/a/3550006/933756 – Quinma 2012-07-16 15:59:17
可能重复[更改JTable中的行的背景颜色](http://stackoverflow.com/questions/3875607/change-the-background-color- )一个排-IN-A-的JTable – 2012-07-16 17:37:08
你可能想通过http://docs.oracle.com/javase/tutorial/uiswing/components/table.html读的[ – MadProgrammer 2012-07-16 18:15:19