글쎄 거기에 몇 가지 방법이 있습니다. 다음은 1입니다. 열 1은 회색으로 표시됩니다.
JTable table = new JTable() {
public Component prepareRenderer(TableCellRenderer renderer,
int rowIndex, int vColIndex) {
Component c = super.prepareRenderer(renderer, rowIndex, vColIndex);
if (vColIndex == 0) {//if first column
c.setBackground(Color.red);
} else {
c.setBackground(Color.green);
}
return c;
}
};
또는 당신은 내가 table.setDefaulRenderer (Color.class, 새로운 CustomTableCellRenderer처럼 호출 한 두 번째 only..i을 사용했다 2
public class CustomTableCellRenderer extends DefaultTableCellRenderer
{
public Component getTableCellRendererComponent (JTable table, Object obj,
boolean isSelected, boolean hasFocus, int row, int column){
Component cell = super.getTableCellRendererComponent(table, obj,
isSelected, hasFocus, row, column);
if (column == 0){
cell.setBackground(Color.red);
}
else{
cell.setBackground(Color.green);
}
return cell;
}
}
안녕을 다음과 같이 클래스의 재정의
DefaultTableCellRenderer
을 가질 수있다()); ..하지만 작동하지 않습니다 .. – shree+1 두 접근법 모두 정상입니다. 여전히 문제가 발생하면 질문을 편집하여 [sscce] (http://sscce.org/)를 포함 시키십시오. 왼쪽에있는 [빈 녹색 체크 표시] (http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work/5235#5235)를 클릭하면이 대답을 수락 할 수 있습니다. – trashgod