我正在使用 NimbusLookAndFeel。有了这种外观和感觉,JTable 的单元格背景交替显示为白色和浅灰色(取决于行号)。现在,我正在编写一些实现 TableCellRenderer 的自定义单元格渲染器。我需要根据单元格在 JTable 中的位置来设置这些渲染器的背景。
public class MyCellRenderer extends JLabel implements TableCellRenderer{
@Override
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
Color bgColor = //need to retrieve the right cell background color
setBackground(bgColor);
return this;
}
}
我怎样才能得到这样的颜色值?