1
我有一個DefaultTableCellRenderer的實現。當某人在表格中選擇一行時,該行將突出顯示爲綠色。如果我想突出顯示所選的那一行,最簡單的方法是什麼?這甚至可以不必重新渲染整個表格?在JTable中繪製行
因此,在這一刻,有我的東西,看起來像這樣:
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
int row, int column) {
Component component = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (isSelected) {
component.setBackground(Color.GREEN);
// Somewhere here I would like to retrieve the row below the current row and give it another color
} else {
component.setBackground(Color.WHITE);
}
return component;
}