の最初の列の値に従って特定の行に色を付けようとしていますJTable
が、以下のコードは行のインデックスに従って行に色を付けます。私のテーブルには 4 つの列しかありません。最初の列には ID 番号があります。これらの ID 番号に従って行に色を付ける必要があります。たとえば、最初の ID が 0 で 2 番目の ID も 0 の場合、両方とも「lightGray」にする必要があります。何かアイデアはありますか?
table_1 = new JTable(){
public Component prepareRenderer(TableCellRenderer renderer,int Index_row, int Index_col) {
Component comp = super.prepareRenderer(renderer,Index_row, Index_col);
//even index, selected or not selected
if (Index_row % 2==0 && !isCellSelected(Index_row, Index_col)) {
comp.setBackground(Color.lightGray);
} else {
comp.setBackground(Color.white);
}
return comp;
}
};
現在の外観は次のとおりです。