class TestTableCellRenderer
extends DefaultTableCellRenderer {
public Component getTableCellRendererComponent(JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row,
int column) {
if(column == 2){//也就是你想变颜色的列
this.setBackground(Color.red);
}
return super.getTableCellRendererComponent(table, value, isSelected,
hasFocus, row, column);}然后你用yourtable.getColumn(2).setCellRenderer(new TestTableCellRenderer());我没有做过测试,你试试吧!
extends DefaultTableCellRenderer {
public Component getTableCellRendererComponent(JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row,
int column) {
if(column == 2){//也就是你想变颜色的列
this.setBackground(Color.red);
}
return super.getTableCellRendererComponent(table, value, isSelected,
hasFocus, row, column);}然后你用yourtable.getColumn(2).setCellRenderer(new TestTableCellRenderer());我没有做过测试,你试试吧!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货