我在我的項目中有一個名爲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