java swing控件JTable 怎么单独设置某一行的颜色
1个回答
展开全部
下面是一个例子的代码:(getTableCellRendererComponent)
colorTableRender colorRender = new colorTableRender ();
table.getColumn("A").setCellRenderer(colorRender);//A,B,C分别代表列名
table.getColumn("B").setCellRenderer(colorRender);
table.getColumn("C").setCellRenderer(colorRender);
public class colorTableRender extends DefaultTableCellRenderer {
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus, int row,
int column) {
Component cell = super.getTableCellRendererComponent(table, value,
isSelected, hasFocus, row, column);
if (row <6) //这里设置行数
cell.setBackground(Color.WHITE);
else
cell.setBackground(new Color(0xee,0xee,0xee));
return cell;
}
}
colorTableRender colorRender = new colorTableRender ();
table.getColumn("A").setCellRenderer(colorRender);//A,B,C分别代表列名
table.getColumn("B").setCellRenderer(colorRender);
table.getColumn("C").setCellRenderer(colorRender);
public class colorTableRender extends DefaultTableCellRenderer {
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus, int row,
int column) {
Component cell = super.getTableCellRendererComponent(table, value,
isSelected, hasFocus, row, column);
if (row <6) //这里设置行数
cell.setBackground(Color.WHITE);
else
cell.setBackground(new Color(0xee,0xee,0xee));
return cell;
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询